Class Cache
Caching for CakePHP.
Copyright: Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
License: License (http://www.opensource.org/licenses/mit-license.php)
Location: cache.php
Properties summary
-
$__config
publicarray
Cache configuration stack Keeps the permanent/default settings for each cache engine. These settings are used to reset the engines after temporary modification.
-
$__name
publicarray
Holds name of the current configuration name being used. -
$__reset
publicarray
Whether to reset the settings with the next call to Cache::set(); -
$_engines
publicarray
Engine instances keyed by configuration name.
Method Summary
-
__destruct() public
Write the session when session data is persisted with cache. -
__loadEngine() public
Tries to find and include a file for a cache engine and returns object instance -
_buildEngine() public
Finds and builds the instance of the required engine class. -
clear() public
Delete all keys from the cache. -
config() public
Set the cache configuration to use. config() can both create new configurations, return the settings for already configured configurations. It also sets the 'default' configuration to use for subsequent operations.
-
configured() public
Returns an array containing the currently configured Cache settings. -
decrement() public
Decrement a number under the key and return decremented value. -
delete() public
Delete a key from the cache. Will automatically use the currently active cache configuration. To set the currently active configuration use Cache::config()
-
drop() public
Drops a cache engine. Deletes the cache configuration information If the deleted configuration is the last configuration using an certain engine, the Engine instance is also unset.
-
gc() public
Garbage collection -
getInstance() public
Returns a singleton instance -
increment() public
Increment a number under the key and return incremented value. -
isInitialized() public
Check if Cache has initialized a working config for the given name. -
read() public
Read a key from the cache. Will automatically use the currently active cache configuration. To set the currently active configuration use Cache::config()
-
set() public
Temporarily change settings to current config options. if no params are passed, resets settings if needed Cache::write() will reset the configuration changes made
-
settings() public
Return the settings for current cache engine. If no name is supplied the settings for the 'active default' configuration will be returned. To set the 'active default' configuration use
Cache::config()
-
write() public
Write data for key into cache. Will automatically use the currently active cache configuration. To set the currently active configuration use Cache::config()
Method Detail
__loadEngine() public ¶
__loadEngine( $name , $plugin = null )
Tries to find and include a file for a cache engine and returns object instance
Parameters
- $name
- of the engine (without 'Engine')
- $plugin optional null
Returns
$engine object or null
_buildEngine() public ¶
_buildEngine( string $name )
Finds and builds the instance of the required engine class.
Parameters
- string $name
- Name of the config array that needs an engine instance built
clear() public ¶
clear( boolean $check = false , string $config = null )
Delete all keys from the cache.
Parameters
- boolean $check optional false
- if true will check expiration, otherwise delete all
- string $config optional null
- name of the configuration to use
Returns
True if the cache was succesfully cleared, false otherwise
config() public ¶
config( string $name = null , array $settings = array() )
Set the cache configuration to use. config() can both create new configurations, return the settings for already configured configurations. It also sets the 'default' configuration to use for subsequent operations.
To create a new configuration:
Cache::config('my_config', array('engine' => 'File', 'path' => TMP));
To get the settings for a configuration, and set it as the currently selected configuration
Cache::config('default');
The following keys are used in core cache engines:
duration
Specify how long items in this cache configuration last.prefix
Prefix appended to all entries. Good for when you need to share a keyspace with either another cache config or annother application.probability
Probability of hitting a cache gc cleanup. Setting to 0 will disable cache::gc from ever being called automatically.- `servers' Used by memcache. Give the address of the memcached servers to use.
compress
Used by memcache. Enables memcache's compressed format.serialize
Used by FileCache. Should cache objects be serialized first.path
Used by FileCache. Path to where cachefiles should be saved.lock
Used by FileCache. Should files be locked before writing to them?user
Used by Xcache. Username for XCachepassword
Used by Xcache. Password for XCache
Parameters
- string $name optional null
- Name of the configuration
- array $settings optional array()
- Optional associative array of settings passed to the engine
Returns
settings) on success, false on failure
See
configured() public ¶
configured( )
Returns an array containing the currently configured Cache settings.
Returns
Array of configured Cache config names.
decrement() public ¶
decrement( string $key , integer $offset = 1 , string $config = null )
Decrement a number under the key and return decremented value.
Parameters
- string $key
- Identifier for the data
- integer $offset optional 1
- How much to substract
- string $config optional null
Optional string configuration name, if not specified the current default config will be used.
Returns
new value, or false if the data doesn't exist, is not integer, or if there was an error fetching it
delete() public ¶
delete( string $key , string $config = null )
Delete a key from the cache. Will automatically use the currently active cache configuration. To set the currently active configuration use Cache::config()
Usage:
Deleting from the active cache configuration.
Cache::delete('my_data');
Deleting from a specific cache configuration.
Cache::delete('my_data', 'long_term');
Parameters
- string $key
- Identifier for the data
- string $config optional null
- name of the configuration to use
Returns
True if the value was succesfully deleted, false if it didn't exist or couldn't be removed
drop() public ¶
drop( string $name )
Drops a cache engine. Deletes the cache configuration information If the deleted configuration is the last configuration using an certain engine, the Engine instance is also unset.
Parameters
- string $name
- A currently configured cache config you wish to remove.
Returns
success of the removal, returns false when the config does not exist.
increment() public ¶
increment( string $key , integer $offset = 1 , string $config = null )
Increment a number under the key and return incremented value.
Parameters
- string $key
- Identifier for the data
- integer $offset optional 1
- How much to add
- string $config optional null
Optional string configuration name. If not specified the current default config will be used.
Returns
new value, or false if the data doesn't exist, is not integer, or if there was an error fetching it.
isInitialized() public ¶
isInitialized( string $name = null , string $config ,… )
Check if Cache has initialized a working config for the given name.
Parameters
- string $name optional null
- $engine Name of the engine
- string $config ,…
- Name of the configuration setting
Returns
Whether or not the config name has been initialized.
read() public ¶
read( string $key , string $config = null )
Read a key from the cache. Will automatically use the currently active cache configuration. To set the currently active configuration use Cache::config()
Usage:
Reading from the active cache configuration.
Cache::read('my_data');
Reading from a specific cache configuration.
Cache::read('my_data', 'long_term');
Parameters
- string $key
- Identifier for the data
- string $config optional null
- optional name of the configuration to use.
Returns
The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
set() public ¶
set( mixed $settings = array() , string $value = null )
Temporarily change settings to current config options. if no params are passed, resets settings if needed Cache::write() will reset the configuration changes made
Parameters
- mixed $settings optional array()
- Optional string for simple name-value pair or array
- string $value optional null
- Optional for a simple name-value pair
Returns
Array of settings.
settings() public ¶
settings( string $name = null )
Return the settings for current cache engine. If no name is supplied the settings
for the 'active default' configuration will be returned. To set the 'active default'
configuration use Cache::config()
Parameters
- string $name optional null
- $engine Name of the configuration to get settings for.
Returns
list of settings for this engine
See
write() public ¶
write( string $key , mixed $value , string $config = null )
Write data for key into cache. Will automatically use the currently active cache configuration. To set the currently active configuration use Cache::config()
Usage:
Writing to the active cache config:
Cache::write('cached_data', $data);
Writing to a specific cache config:
Cache::write('cached_data', $data, 'long_term');
Parameters
- string $key
- Identifier for the data
- mixed $value
- Data to be cached - anything except a resource
- string $config optional null
- Optional string configuration name to write to.
Returns
True if the data was successfully cached, false on failure