yii\caching\Cache::add PHP Method

add() public method

Nothing will be done if the cache already contains the key.
public add ( mixed $key, mixed $value, integer $duration, yii\caching\Dependency $dependency = null ) : boolean
$key mixed a key identifying the value to be cached. This can be a simple string or a complex data structure consisting of factors representing the key.
$value mixed the value to be cached
$duration integer the number of seconds in which the cached value will expire. 0 means never expire.
$dependency yii\caching\Dependency dependency of the cached item. If the dependency changes, the corresponding value in the cache will be invalidated when it is fetched via [[get()]]. This parameter is ignored if [[serializer]] is false.
return boolean whether the value is successfully stored into cache
    public function add($key, $value, $duration = 0, $dependency = null)
    {
        if ($dependency !== null && $this->serializer !== false) {
            $dependency->evaluateDependency($this);
        }
        if ($this->serializer === null) {
            $value = serialize([$value, $dependency]);
        } elseif ($this->serializer !== false) {
            $value = call_user_func($this->serializer[0], [$value, $dependency]);
        }
        $key = $this->buildKey($key);
        return $this->addValue($key, $value, $duration);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * @param mixed      $key
  * @param mixed      $value
  * @param integer    $duration
  * @param Dependency $dependency
  *
  * @return boolean
  *
  * @see yii\caching\Cache::add()
  */
 public function add($key, $value, $duration = 0, $dependency = NULL)
 {
     return $this->cache->add($key, $value, $duration, $dependency);
 }
All Usage Examples Of yii\caching\Cache::add