Provides static/global access to a zend cache manager instance as well as easy access to load/save/etc.
More...
List of all members.
Static Public Member Functions |
static | canCache ($template= 'default') |
| Check if the given template is registered with the cache manager.
|
static | clean ($mode= 'all', $tags=array(), $template=null) |
| Clean cache entries.
|
static | getCache ($template= 'default') |
| A convienence passthrough to the getCache method on the cache manager.
|
static | getManager () |
| Get the configured cache manager instance.
|
static | hasManager () |
| Check if a cache manager is configured.
|
static | load ($id, $template= 'default') |
| Fetch data from the cache by id.
|
static | remove ($id, $template= 'default') |
| Remove a entry from the cache.
|
static | save ($data, $id, $tags=array(), $lifetime=false, $priority=8, $template= 'default') |
| Save some data in the cache.
|
static | setLoggingEnabled ($enabled=true) |
| Enable/disable logging when unable to read/write the cache.
|
static | setManager (Zend_Cache_Manager $manager=null) |
| Set the cache manager to use.
|
Static Protected Attributes |
static | $_loggingEnabled = true |
static | $_manager = null |
Detailed Description
Provides static/global access to a zend cache manager instance as well as easy access to load/save/etc.
against named cache manager templates.
- Copyright:
- 2011-2012 Perforce Software. All rights reserved
- License:
- Please see LICENSE.txt in top-level folder of this distribution.
- Version:
- 2012.2/486814
Member Function Documentation
static P4Cms_Cache::canCache |
( |
$ |
template = 'default' | ) |
[static] |
Check if the given template is registered with the cache manager.
Returns false template is invalid, or no manager is set.
- Parameters:
-
string | $template | optional - the named cache configuration to use. |
- Returns:
- bool true if template and manager are valid.
{
if (!static::hasManager()) {
if (static::$_loggingEnabled) {
P4Cms_Log::log(
"Cannot read/write cache. No cache manager has been set.",
P4Cms_Log::WARN
);
}
return false;
}
$manager = static::getManager();
if (!$manager->hasCache($template)) {
if (static::$_loggingEnabled) {
P4Cms_Log::log(
"Cannot read/write cache. Cache template $template is not configured.",
P4Cms_Log::WARN
);
}
return false;
}
return true;
}
static P4Cms_Cache::clean |
( |
$ |
mode = 'all' , |
|
|
$ |
tags = array() , |
|
|
$ |
template = null |
|
) |
| [static] |
Clean cache entries.
If a template is specified only it will be affected otherwise all templates are cleared.
Available modes are : 'all' (default) => remove all cache entries ($tags is not used) 'old' => remove too old cache entries ($tags is not used) 'matchingTag' => remove cache entries matching all given tags ($tags can be an array of strings or a single string) 'notMatchingTag' => remove cache entries not matching one of the given tags ($tags can be an array of strings or a single string) 'matchingAnyTag' => remove cache entries matching any given tags ($tags can be an array of strings or a single string)
- Parameters:
-
string | $mode | optional - the clearing mode, see above |
array | string | $tags | optional - tags to use as per clearing mode |
string | null | $template | optional - template to limit to, all if null |
- Returns:
- boolean True if ok
{
if (!static::hasManager()) {
return false;
}
if (is_string($tags)) {
$tags = array($tags);
}
$templates = static::getManager()->getCaches();
if ($template != null) {
if (!static::canCache($template)) {
return false;
}
$templates = array(static::getCache($template));
}
$result = true;
foreach ($templates as $template) {
try {
$result = $template->clean($mode, $tags) && $result;
} catch (Zend_Cache_Exception $e) {
$result = false;
}
}
return $result;
}
static P4Cms_Cache::getCache |
( |
$ |
template = 'default' | ) |
[static] |
A convienence passthrough to the getCache method on the cache manager.
- Parameters:
-
string | $template | The template name to pass to manager's getCache |
- Returns:
- Zend_Cache_Core|false Returns the result of manager getCache or false if no manager
{
if (!static::canCache($template)) {
return false;
}
return static::getManager()->getCache($template);
}
static P4Cms_Cache::getManager |
( |
| ) |
[static] |
Get the configured cache manager instance.
- Returns:
- Zend_Cache_Manager the configured zend cache manager instance.
- Exceptions:
-
static P4Cms_Cache::hasManager |
( |
| ) |
[static] |
Check if a cache manager is configured.
- Returns:
- bool true if a manager instance is set.
{
return static::$_manager instanceof Zend_Cache_Manager;
}
static P4Cms_Cache::load |
( |
$ |
id, |
|
|
$ |
template = 'default' |
|
) |
| [static] |
Fetch data from the cache by id.
Returns false if no such id in the cache or if cache manager or named template are not configured.
- Parameters:
-
string | $id | the id of the cache entry. |
string | $template | optional - the cache configuration to use defaults to 'default'. |
- Returns:
- mixed|false the cached data or false if no such entry or cache manager/template not configured.
{
if (!static::canCache($template)) {
return false;
}
$cache = static::getManager()->getCache($template);
return $cache->load($id);
}
static P4Cms_Cache::remove |
( |
$ |
id, |
|
|
$ |
template = 'default' |
|
) |
| [static] |
Remove a entry from the cache.
- Parameters:
-
string | $id | id of entry to remove. |
string | $template | optional - the named cache configuration to use. |
- Returns:
- bool true if entry removed; false otherwise.
{
if (!static::canCache($template)) {
return false;
}
$cache = static::getManager()->getCache($template);
return $cache->remove($id);
}
static P4Cms_Cache::save |
( |
$ |
data, |
|
|
$ |
id, |
|
|
$ |
tags = array() , |
|
|
$ |
lifetime = false , |
|
|
$ |
priority = 8 , |
|
|
$ |
template = 'default' |
|
) |
| [static] |
Save some data in the cache.
Returns false if cache manager or template are not configured.
- Parameters:
-
mixed | $data | data to put in cache (must be string if automatic serialization is off) |
string | $id | cache id (if not set, the last cache id will be used) |
array | $tags | cache tags |
int | $lifetime | a specific lifetime for this cache record (null => infinite lifetime) |
int | $priority | integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends |
string | $template | optional - the named cache configuration to use. |
- Returns:
- bool true if save successful, false otherwise.
{
if (!static::canCache($template)) {
return false;
}
$cache = static::getManager()->getCache($template);
return $cache->save($data, $id, $tags, $lifetime, $priority);
}
static P4Cms_Cache::setLoggingEnabled |
( |
$ |
enabled = true | ) |
[static] |
Enable/disable logging when unable to read/write the cache.
- Parameters:
-
bool | $enabled | true to enable logging, false otherwise. |
{
static::$_loggingEnabled = (bool) $enabled;
}
static P4Cms_Cache::setManager |
( |
Zend_Cache_Manager $ |
manager = null | ) |
[static] |
Set the cache manager to use.
- Parameters:
-
Zend_Cache_Manager | $manager | the cache manager instance to use. |
{
static::$_manager = $manager;
}
Member Data Documentation
P4Cms_Cache::$_loggingEnabled = true [static, protected] |
P4Cms_Cache::$_manager = null [static, protected] |
The documentation for this class was generated from the following file: