yii\caching\Cache::set PHP Method

set() public method

If the cache already contains such a key, the existing value and expiration time will be replaced with the new ones, respectively.
public set ( mixed $key, mixed $value, integer $duration = null, 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 default duration in seconds before the cache will expire. If not set, default [[ttl]] value is used.
$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 set($key, $value, $duration = null, $dependency = null)
    {
        if ($duration === null) {
            $duration = $this->defaultDuration;
        }
        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->setValue($key, $value, $duration);
    }

Usage Example

コード例 #1
0
 public function buildSitemapUrl($name)
 {
     $urls = $this->urls;
     $sitemapData = $this->createControllerByID('default')->renderPartial('sitemap', ['urls' => $urls]);
     $this->cacheProvider->set($this->cacheKey, $sitemapData, $this->cacheExpire);
     return $sitemapData;
 }
All Usage Examples Of yii\caching\Cache::set