Doctrine 1.2.4
Doctrine_Cache_Xcache Class Reference

Inherits Doctrine_Cache_Driver.

Public Member Functions

 __construct ($options=array())
 
 contains ($id)
 
 delete ($id)
 
 deleteAll ()
 
 deleteByPrefix ($prefix)
 
 deleteByRegex ($regex)
 
 deleteBySuffix ($suffix)
 
 fetch ($id, $testCacheValidity=true)
 
 getOption ($option)
 
 save ($id, $data, $lifeTime=false)
 
 setOption ($option, $value)
 

Protected Member Functions

 _doContains ($id)
 
 _doDelete ($id)
 
 _doFetch ($id, $testCacheValidity=true)
 
 _doSave ($id, $data, $lifeTime=false)
 
 _getCacheKeys ()
 
 _getKey ($id)
 
 checkAuth ()
 

Detailed Description

Definition at line 35 of file Xcache.php.

Constructor & Destructor Documentation

Doctrine_Cache_Xcache::__construct (   $options = array())

constructor

Parameters
array$optionsassociative array of cache driver options

Definition at line 42 of file Xcache.php.

{
if ( ! extension_loaded('xcache') ) {
throw new Doctrine_Cache_Exception('In order to use Xcache driver, the xcache extension must be loaded.');
}
parent::__construct($options);
}

Member Function Documentation

Doctrine_Cache_Xcache::_doContains (   $id)
protected

Test if a cache is available or not (for the given id)

Parameters
string$idcache id
Returns
mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record

Definition at line 68 of file Xcache.php.

{
return xcache_isset($id);
}
Doctrine_Cache_Xcache::_doDelete (   $id)
protected

Remove a cache record directly. This method is implemented by the cache drivers and used in Doctrine_Cache_Driver::delete()

Parameters
string$idcache id
Returns
boolean true if no problem

Definition at line 94 of file Xcache.php.

{
return xcache_unset($id);
}
Doctrine_Cache_Xcache::_doFetch (   $id,
  $testCacheValidity = true 
)
protected

Test if a cache record exists for the passed id

Parameters
string$idcache id
Returns
mixed Returns either the cached data or false

Definition at line 57 of file Xcache.php.

{
return $this->_doContains($id) ? xcache_get($id) : false;
}
Doctrine_Cache_Xcache::_doSave (   $id,
  $data,
  $lifeTime = false 
)
protected

Save a cache record directly. This method is implemented by the cache drivers and used in Doctrine_Cache_Driver::save()

Parameters
string$idcache id
string$datadata to cache
int$lifeTimeif != false, set a specific lifetime for this cache record (null => infinite lifeTime)
Returns
boolean true if no problem

Definition at line 82 of file Xcache.php.

{
return xcache_set($id, $data, $lifeTime);
}
Doctrine_Cache_Xcache::_getCacheKeys ( )
protected

Fetch an array of all keys stored in cache

Returns
array Returns the array of cache keys

Definition at line 104 of file Xcache.php.

{
$this->checkAuth();
$keys = array();
for ($i = 0, $count = xcache_count(XC_TYPE_VAR); $i < $count; $i++) {
$entries = xcache_list(XC_TYPE_VAR, $i);
if (is_array($entries['cache_list'])) {
foreach ($entries['cache_list'] as $entry) {
$keys[] = $entry['name'];
}
}
}
return $keys;
}
Doctrine_Cache_Driver::_getKey (   $id)
protectedinherited

Get the hash key passing its suffix

Parameters
string$idThe hash key suffix
Returns
string Hash key to be used by drivers

Definition at line 226 of file Driver.php.

{
$prefix = isset($this->_options['prefix']) ? $this->_options['prefix'] : '';
if ( ! $prefix || strpos($id, $prefix) === 0) {
return $id;
} else {
return $prefix . $id;
}
}
Doctrine_Cache_Xcache::checkAuth ( )
protected

Checks that xcache.admin.enable_auth is Off

Exceptions
Doctrine_Cache_ExceptionWhen xcache.admin.enable_auth is On
Returns
void

Definition at line 125 of file Xcache.php.

{
if (ini_get('xcache.admin.enable_auth')) {
throw new Doctrine_Cache_Exception('To use all features of Doctrine_Cache_Xcache, you must set "xcache.admin.enable_auth" to "Off" in your php.ini.');
}
}
Doctrine_Cache_Driver::contains (   $id)
inherited

Test if a cache record exists for the passed id

Parameters
string$idcache id
Returns
mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record

Definition at line 101 of file Driver.php.

{
$key = $this->_getKey($id);
return $this->_doContains($key);
}
Doctrine_Cache_Driver::delete (   $id)
inherited

Remove a cache record

Note: This method accepts wildcards with the * character

Parameters
string$idcache id
Returns
boolean true if no problem

Definition at line 129 of file Driver.php.

{
$key = $this->_getKey($id);
if (strpos($key, '*') !== false) {
return $this->deleteByRegex('/' . str_replace('*', '.*', $key) . '/');
}
return $this->_doDelete($key);
}
Doctrine_Cache_Driver::deleteAll ( )
inherited

Delete all cache entries from the cache driver

Returns
integer $count The number of deleted cache entries

Definition at line 208 of file Driver.php.

{
$count = 0;
if (is_array($keys = $this->_getCacheKeys())) {
foreach ($keys as $key) {
$count++;
$this->delete($key);
}
}
return $count;
}
Doctrine_Cache_Driver::deleteByPrefix (   $prefix)
inherited

Delete cache entries where the key has the passed prefix

Parameters
string$prefix
Returns
integer $count The number of deleted cache entries

Definition at line 167 of file Driver.php.

{
$count = 0;
$keys = $this->_getCacheKeys();
if (is_array($keys)) {
foreach ($keys as $key) {
if (strpos($key, $prefix) === 0) {
$count++;
$this->delete($key);
}
}
}
return $count;
}
Doctrine_Cache_Driver::deleteByRegex (   $regex)
inherited

Delete cache entries where the key matches a PHP regular expressions

Parameters
string$regex
Returns
integer $count The number of deleted cache entries

Definition at line 146 of file Driver.php.

{
$count = 0;
$keys = $this->_getCacheKeys();
if (is_array($keys)) {
foreach ($keys as $key) {
if (preg_match($regex, $key)) {
$count++;
$this->delete($key);
}
}
}
return $count;
}
Doctrine_Cache_Driver::deleteBySuffix (   $suffix)
inherited

Delete cache entries where the key has the passed suffix

Parameters
string$suffix
Returns
integer $count The number of deleted cache entries

Definition at line 188 of file Driver.php.

{
$count = 0;
$keys = $this->_getCacheKeys();
if (is_array($keys)) {
foreach ($keys as $key) {
if (substr($key, -1 * strlen($suffix)) == $suffix) {
$count++;
$this->delete($key);
}
}
}
return $count;
}
Doctrine_Cache_Driver::fetch (   $id,
  $testCacheValidity = true 
)
inherited

Fetch a cache record from this cache driver instance

Parameters
string$idcache id
boolean$testCacheValidityif set to false, the cache validity won't be tested
Returns
mixed Returns either the cached data or false

Definition at line 89 of file Driver.php.

{
$key = $this->_getKey($id);
return $this->_doFetch($key, $testCacheValidity);
}
Doctrine_Cache_Driver::getOption (   $option)
inherited

Get value of option

Parameters
mixed$optionthe option name
Returns
mixed option value

Definition at line 73 of file Driver.php.

{
if ( ! isset($this->_options[$option])) {
return null;
}
return $this->_options[$option];
}
Doctrine_Cache_Driver::save (   $id,
  $data,
  $lifeTime = false 
)
inherited

Save some string datas into a cache record

Parameters
string$idcache id
string$datadata to cache
int$lifeTimeif != false, set a specific lifetime for this cache record (null => infinite lifeTime)
Returns
boolean true if no problem

Definition at line 115 of file Driver.php.

{
$key = $this->_getKey($id);
return $this->_doSave($key, $data, $lifeTime);
}
Doctrine_Cache_Driver::setOption (   $option,
  $value 
)
inherited

Set option name and value

Parameters
mixed$optionthe option name
mixed$valueoption value
Returns
boolean TRUE on success, FALSE on failure

Definition at line 58 of file Driver.php.

{
if (isset($this->_options[$option])) {
$this->_options[$option] = $value;
return true;
}
return false;
}

The documentation for this class was generated from the following file: