Caching

Functions


// Set data to cache. 
cache_set($key, $data);

// Example with 'dependency'.
// Cache the category until will not be deleted, updated or created a new category. 
cache_set($key, $data, $expire = 86400, 'category');

boolean cache_set ( $key, $data, $expire = 86400, $dependency = null )
$key string The key to indicate the value
$data mixed the value you want to store
$expire integer (optional) this defines how many seconds to keep the cache for.
$dependency string/array (optional) yii\caching\TagDependency. Available dependency tags ('post', 'category', 'album', 'photo', 'language', 'menu', 'menu_type', 'page', 'settings', 'user', 'profile');

// The main difference of cache_set that function adds data to the cache if the cache key doesn't already exist. If it does exist, the data is not added. 

boolean cache_add ( $key, $data, $expire = 86400, $dependency = null )
$key string The key to indicate the value
$data mixed the value you want to store
$expire integer (optional) this defines how many seconds to keep the cache for.
$dependency string/array (optional) yii\caching\TagDependency. Available tags ('post', 'category', 'album', 'photo', 'language', 'menu', 'menu_type', 'page', 'settings', 'user', 'profile');

// Returns the value of the cached object, or false if the cache key doesn't exist. 

// Examples. 
$result = cache_get('key');
if (false === cache_get('key')) {
    $result = 'data';
    cache_set('my_result', $result);
}

mixed cache_get ( $key )
$key string The key to indicate the value
Returns the value of the cached object, or false if the cache key doesn't exist.

// Clears data from the cache for the given key. 

boolean cache_delete ( $key )
$key string The key to indicate the value

// Returns a value indicating whether the specified key is found in the cache.. 

boolean cache_exists ( $key )
$key string The key to indicate the value

// Clears all cached data. 

cache_flush ( $key )
$key string The key to indicate the value