yii\caching\FileCache::setValue PHP Method

setValue() protected method

This is the implementation of the method declared in the parent class.
protected setValue ( string $key, string $value, integer $duration ) : boolean
$key string the key identifying the value to be cached
$value string the value to be cached. Other types (If you have disabled [[serializer]]) unable to get is correct in [[getValue()]].
$duration integer the number of seconds in which the cached value will expire. 0 means never expire.
return boolean true if the value is successfully stored into cache, false otherwise
    protected function setValue($key, $value, $duration)
    {
        $this->gc();
        $cacheFile = $this->getCacheFile($key);
        if ($this->directoryLevel > 0) {
            @FileHelper::createDirectory(dirname($cacheFile), $this->dirMode, true);
        }
        if (@file_put_contents($cacheFile, $value, LOCK_EX) !== false) {
            if ($this->fileMode !== null) {
                @chmod($cacheFile, $this->fileMode);
            }
            if ($duration <= 0) {
                $duration = 31536000;
                // 1 year
            }
            return @touch($cacheFile, $duration + time());
        } else {
            $error = error_get_last();
            Yii::warning("Unable to write cache file '{$cacheFile}': {$error['message']}", __METHOD__);
            return false;
        }
    }

Usage Example

Example #1
0
 protected function setValue($key, $value, $duration)
 {
     $value = base64_encode($value);
     parent::setValue($key, $value, $duration);
 }
All Usage Examples Of yii\caching\FileCache::setValue