PHP Класс yii\caching\FileCache

For each data value being cached, FileCache will store it in a separate file. The cache files are placed under [[cachePath]]. FileCache will perform garbage collection automatically to remove expired cache files. Please refer to Cache for common cache operations that are supported by FileCache.
С версии: 2.0
Автор: Qiang Xue ([email protected])
Наследование: extends Cache
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$cacheFileSuffix cache file suffix. Defaults to '.bin'.
$cachePath the directory to store cache files. You may use path alias here. If not set, it will use the "cache" subdirectory under the application runtime path.
$dirMode the permission to be set for newly created directories. This value will be used by PHP chmod() function. No umask will be applied. Defaults to 0775, meaning the directory is read-writable by owner and group, but read-only for other users.
$directoryLevel the level of sub-directories to store cache files. Defaults to 1. If the system has huge number of cache files (e.g. one million), you may use a bigger value (usually no bigger than 3). Using sub-directories is mainly to ensure the file system is not over burdened with a single directory having too many files.
$fileMode the permission to be set for newly created cache files. This value will be used by PHP chmod() function. No umask will be applied. If not set, the permission will be determined by the current environment.
$gcProbability the probability (parts per million) that garbage collection (GC) should be performed when storing a piece of data in the cache. Defaults to 10, meaning 0.001% chance. This number should be between 0 and 1000000. A value 0 means no GC will be performed at all.
$keyPrefix a string prefixed to every cache key. This is needed when you store cache data under the same [[cachePath]] for different applications to avoid conflict. To ensure interoperability, only alphanumeric characters should be used.

Открытые методы

Метод Описание
exists ( mixed $key ) : boolean Checks whether a specified key exists in the cache.
gc ( boolean $force = false, boolean $expiredOnly = true ) Removes expired cache files.
init ( ) Initializes this component by ensuring the existence of the cache path.

Защищенные методы

Метод Описание
addValue ( string $key, string $value, integer $duration ) : boolean Stores a value identified by a key into cache if the cache does not contain this key.
deleteValue ( string $key ) : boolean Deletes a value with the specified key from cache This is the implementation of the method declared in the parent class.
flushValues ( ) : boolean Deletes all values from cache.
gcRecursive ( string $path, boolean $expiredOnly ) Recursively removing expired cache files under a directory.
getCacheFile ( string $key ) : string Returns the cache file path given the cache key.
getValue ( string $key ) : string | false Retrieves a value from cache with a specified key.
setValue ( string $key, string $value, integer $duration ) : boolean Stores a value identified by a key in cache.

Описание методов

addValue() защищенный Метод

This is the implementation of the method declared in the parent class.
protected addValue ( 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.
Результат boolean true if the value is successfully stored into cache, false otherwise

deleteValue() защищенный Метод

Deletes a value with the specified key from cache This is the implementation of the method declared in the parent class.
protected deleteValue ( string $key ) : boolean
$key string the key of the value to be deleted
Результат boolean if no error happens during deletion

exists() публичный Метод

This can be faster than getting the value from the cache if the data is big. Note that this method does not check whether the dependency associated with the cached data, if there is any, has changed. So a call to [[get]] may return false while exists returns true.
public exists ( mixed $key ) : boolean
$key mixed a key identifying the cached value. This can be a simple string or a complex data structure consisting of factors representing the key.
Результат boolean true if a value exists in cache, false if the value is not in the cache or expired.

flushValues() защищенный Метод

This is the implementation of the method declared in the parent class.
protected flushValues ( ) : boolean
Результат boolean whether the flush operation was successful.

gc() публичный Метод

Removes expired cache files.
public gc ( boolean $force = false, boolean $expiredOnly = true )
$force boolean whether to enforce the garbage collection regardless of [[gcProbability]]. Defaults to false, meaning the actual deletion happens with the probability as specified by [[gcProbability]].
$expiredOnly boolean whether to removed expired cache files only. If false, all cache files under [[cachePath]] will be removed.

gcRecursive() защищенный Метод

This method is mainly used by FileCache::gc.
protected gcRecursive ( string $path, boolean $expiredOnly )
$path string the directory under which expired cache files are removed.
$expiredOnly boolean whether to only remove expired cache files. If false, all files under `$path` will be removed.

getCacheFile() защищенный Метод

Returns the cache file path given the cache key.
protected getCacheFile ( string $key ) : string
$key string cache key
Результат string the cache file path

getValue() защищенный Метод

This is the implementation of the method declared in the parent class.
protected getValue ( string $key ) : string | false
$key string a unique key identifying the cached value
Результат string | false the value stored in cache, false if the value is not in the cache or expired.

init() публичный Метод

Initializes this component by ensuring the existence of the cache path.
public init ( )

setValue() защищенный Метод

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.
Результат boolean true if the value is successfully stored into cache, false otherwise

Описание свойств

$cacheFileSuffix публичное свойство

cache file suffix. Defaults to '.bin'.
public $cacheFileSuffix

$cachePath публичное свойство

the directory to store cache files. You may use path alias here. If not set, it will use the "cache" subdirectory under the application runtime path.
public $cachePath

$dirMode публичное свойство

the permission to be set for newly created directories. This value will be used by PHP chmod() function. No umask will be applied. Defaults to 0775, meaning the directory is read-writable by owner and group, but read-only for other users.
public $dirMode

$directoryLevel публичное свойство

the level of sub-directories to store cache files. Defaults to 1. If the system has huge number of cache files (e.g. one million), you may use a bigger value (usually no bigger than 3). Using sub-directories is mainly to ensure the file system is not over burdened with a single directory having too many files.
public $directoryLevel

$fileMode публичное свойство

the permission to be set for newly created cache files. This value will be used by PHP chmod() function. No umask will be applied. If not set, the permission will be determined by the current environment.
public $fileMode

$gcProbability публичное свойство

the probability (parts per million) that garbage collection (GC) should be performed when storing a piece of data in the cache. Defaults to 10, meaning 0.001% chance. This number should be between 0 and 1000000. A value 0 means no GC will be performed at all.
public $gcProbability

$keyPrefix публичное свойство

a string prefixed to every cache key. This is needed when you store cache data under the same [[cachePath]] for different applications to avoid conflict. To ensure interoperability, only alphanumeric characters should be used.
public $keyPrefix