Class CFileCache
CFileCache provides a file-based caching mechanism.
For each data value being cached, CFileCache will use store it in a separate
file under CFileCache::$cachePath
which defaults to 'protected/runtime/cache'.
CFileCache will perform garbage collection automatically to remove expired cache
files.
See CCache
manual for common cache operations that are supported by
CFileCache.
-
CComponent
-
CApplicationComponent
implements
IApplicationComponent
-
CCache
implements
ICache,
ArrayAccess
-
CFileCache
Methods summary
public
|
|
public
integer
|
#
getGCProbability( )
Returns
integer the probability (parts per million) that garbage collection (GC) should be
performed when storing a piece of data in the cache. Defaults to 100, meaning
0.01% chance.
|
public
|
#
setGCProbability( integer $value )
Parameters
- $value
integer $value the probability (parts per million) that garbage collection (GC) should
be performed when storing a piece of data in the cache. Defaults to 100, meaning
0.01% chance. This number should be between 0 and 1000000. A value 0 meaning no
GC will be performed at all.
|
protected
boolean
|
#
flushValues( )
Deletes all values from cache. This is the implementation of the method
declared in the parent class.
Deletes all values from cache. This is the implementation of the method
declared in the parent class.
Returns
boolean whether the flush operation was successful.
Throws
CException
if this method is not overridden by child classes
Since
1.1.5
Overrides
|
protected
string|boolean
|
#
getValue( string $key )
Retrieves a value from cache with a specified key. This is the implementation
of the method declared in the parent class.
Retrieves a value from cache with a specified key. This is the implementation
of the method declared in the parent class.
Parameters
- $key
string $key a unique key identifying the cached value
Returns
string|boolean the value stored in cache, false if the value is not in the cache or expired.
Throws
CException
if this method is not overridden by child classes
Overrides
|
protected
boolean
|
#
setValue( string $key, string $value, integer $expire )
Stores a value identified by a key in cache. This is the implementation of
the method declared in the parent class.
Stores a value identified by a key in cache. This is the implementation of
the method declared in the parent class.
Parameters
- $key
string $key the key identifying the value to be cached
- $value
string $value the value to be cached
- $expire
integer $expire the number of seconds in which the cached value will expire. 0 means
never expire.
Returns
boolean true if the value is successfully stored into cache, false otherwise
Throws
CException
if this method is not overridden by child classes
Overrides
|
protected
boolean
|
#
addValue( string $key, string $value, integer $expire )
Stores a value identified by a key into cache if the cache does not contain
this key. This is the implementation of the method declared in the parent
class.
Stores a value identified by a key into cache if the cache does not contain
this key. This is the implementation of the method declared in the parent
class.
Parameters
- $key
string $key the key identifying the value to be cached
- $value
string $value the value to be cached
- $expire
integer $expire the number of seconds in which the cached value will expire. 0 means
never expire.
Returns
boolean true if the value is successfully stored into cache, false otherwise
Throws
CException
if this method is not overridden by child classes
Overrides
|
protected
boolean
|
#
deleteValue( string $key )
Deletes a value with the specified key from cache This is the implementation
of the method declared in the parent class.
Deletes a value with the specified key from cache This is the implementation
of the method declared in the parent class.
Parameters
- $key
string $key the key of the value to be deleted
Returns
boolean if no error happens during deletion
Throws
CException
if this method is not overridden by child classes
Overrides
|
protected
string
|
#
getCacheFile( string $key )
Returns the cache file path given the cache key.
Returns the cache file path given the cache key.
Parameters
- $key
string $key cache key
Returns
string the cache file path
|
public
|
#
gc( boolean $expiredOnly = true, string $path = null )
Removes expired cache files.
Removes expired cache files.
Parameters
- $expiredOnly
boolean $expiredOnly whether only expired cache files should be removed. If false, all
cache files under CFileCache::$cachePath will be removed.
- $path
string $path the path to clean with. If null, it will be CFileCache::$cachePath .
|
Methods inherited from CCache
add(),
delete(),
flush(),
generateUniqueKey(),
get(),
getValues(),
mget(),
offsetExists(),
offsetGet(),
offsetSet(),
offsetUnset(),
set()
|
Methods inherited from CComponent
__call(),
__get(),
__isset(),
__set(),
__unset(),
asa(),
attachBehavior(),
attachBehaviors(),
attachEventHandler(),
canGetProperty(),
canSetProperty(),
detachBehavior(),
detachBehaviors(),
detachEventHandler(),
disableBehavior(),
disableBehaviors(),
enableBehavior(),
enableBehaviors(),
evaluateExpression(),
getEventHandlers(),
hasEvent(),
hasEventHandler(),
hasProperty(),
raiseEvent()
|
Properties summary
public
string
|
$cachePath
|
|
#
the directory to store cache files. Defaults to null, meaning using
'protected/runtime/cache' as the directory.
the directory to store cache files. Defaults to null, meaning using
'protected/runtime/cache' as the directory.
|
public
integer
|
$cachePathMode
|
0777 |
#
the permission to be set for directory to store cache files This value will
be used by PHP chmod function. Defaults to 0777, meaning the directory can be
read, written and executed by all users.
the permission to be set for directory to store cache files This value will
be used by PHP chmod function. Defaults to 0777, meaning the directory can be
read, written and executed by all users.
Since
1.1.16
|
public
string
|
$cacheFileSuffix
|
'.bin' |
#
cache file suffix. Defaults to '.bin'.
cache file suffix. Defaults to '.bin'.
|
public
integer
|
$cacheFileMode
|
0666 |
#
the permission to be set for new cache files. This value will be used by PHP
chmod function. Defaults to 0666, meaning the file is read-writable by all
users.
the permission to be set for new cache files. This value will be used by PHP
chmod function. Defaults to 0666, meaning the file is read-writable by all
users.
Since
1.1.16
|
public
integer
|
$directoryLevel
|
0 |
#
the level of sub-directories to store cache files. Defaults to 0, meaning no
sub-directories. If the system has huge number of cache files (e.g. 10K+), you
may want to set this value to be 1 or 2 so that the file system is not over
burdened. The value of this property should not exceed 16 (less than 3 is
recommended).
the level of sub-directories to store cache files. Defaults to 0, meaning no
sub-directories. If the system has huge number of cache files (e.g. 10K+), you
may want to set this value to be 1 or 2 so that the file system is not over
burdened. The value of this property should not exceed 16 (less than 3 is
recommended).
|
public
boolean
|
$embedExpiry
|
false |
#
whether cache entry expiration time should be embedded into a physical file.
Defaults to false meaning that the file modification time will be used to store
expire value. True value means that first ten bytes of the file would be
reserved and used to store expiration time. On some systems PHP is not allowed
to change file modification time to be in future even with 777 permissions, so
this property could be useful in this case.
whether cache entry expiration time should be embedded into a physical file.
Defaults to false meaning that the file modification time will be used to store
expire value. True value means that first ten bytes of the file would be
reserved and used to store expiration time. On some systems PHP is not allowed
to change file modification time to be in future even with 777 permissions, so
this property could be useful in this case.
Since
1.1.14
|
Magic properties summary
public
integer
|
$gCProbability
|
#
The probability (parts per million) that garbage collection (GC) should be
performed when storing a piece of data in the cache. Defaults to 100, meaning
0.01% chance.
The probability (parts per million) that garbage collection (GC) should be
performed when storing a piece of data in the cache. Defaults to 100, meaning
0.01% chance.
|