add() public method

This operation fails (returns false) if the key already exists in cache. If the operation succeeds, true will be returned.
public add ( string $key, mixed $value, integer $expire ) : boolean
$key string
$value mixed
$expire integer Time when item falls out of the cache: 0 = permanent (doesn't expires); under 2592000 (30 days) = relative time, in seconds from now; over 2592000 = absolute time, unix timestamp
return boolean
Esempio n. 1
0
 /**
  * As soon as a key turns up empty (doesn't yet exist in cache), we'll
  * "protect" it for some time. This will be done by writing to a key similar
  * to the original key name. If this key is present (which it will only be
  * for a short amount of time) we'll know it's protected.
  *
  * @param array $keys
  *
  * @return string[] Array of keys that were successfully protected
  */
 protected function protect(array $keys)
 {
     if (empty($keys)) {
         return array();
     }
     $success = array();
     foreach ($keys as $key) {
         /*
          * Key is add()ed because there may be multiple concurrent processes
          * that are both in the process of protecting - first one to add()
          * wins (and those are returned by the function, so those that are
          * failed to protect can be considered protected)
          */
         $success[$key] = $this->cache->add($this->stampedeKey($key), '', $this->sla);
     }
     return array_keys(array_filter($success));
 }