Kevinrob\GuzzleCache\CacheEntry::getTTL PHP Méthode

getTTL() public méthode

public getTTL ( ) : integer
Résultat integer TTL in seconds (0 = infinite)
    public function getTTL()
    {
        if ($this->hasValidationInformation()) {
            // No TTL if we have a way to re-validate the cache
            return 0;
        }
        if ($this->staleIfErrorTo !== null) {
            // Keep it when stale if error
            $ttl = $this->staleIfErrorTo->getTimestamp() - time();
        } else {
            // Keep it until it become stale
            $ttl = $this->staleAt->getTimestamp() - time();
        }
        // Don't return 0, it's reserved for infinite TTL
        return $ttl !== 0 ? (int) $ttl : -1;
    }

Usage Example

 /**
  * {@inheritdoc}
  */
 public function save($key, CacheEntry $data)
 {
     try {
         $lifeTime = $data->getTTL();
         if ($lifeTime >= 0) {
             return $this->cache->save($key, gzcompress(serialize($data)), $lifeTime);
         }
     } catch (\Exception $ignored) {
         // No fail if we can't save it the storage
     }
     return false;
 }
All Usage Examples Of Kevinrob\GuzzleCache\CacheEntry::getTTL