Created
August 7, 2010 14:10
-
-
Save n1k0/512851 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This Doctrine Cache Apc class adds a 'prefix' option in order to handle | |
* different APC environments or setups for storing query and cache results | |
* | |
* @author Nicolas Perriault | |
* @license WTFPL | |
*/ | |
class Doctrine_Cache_Namespaced_Apc extends Doctrine_Cache_Apc | |
{ | |
/** | |
* Computes cache key from an id and configured prefix | |
* | |
* @param string $id cache id | |
* @return string | |
*/ | |
protected function computeId($id) | |
{ | |
return $this->getOption('prefix').$id; | |
} | |
/** | |
* Fetch a cache record from this cache driver instance | |
* | |
* @param string $id cache id | |
* @param boolean $testCacheValidity if set to false, the cache validity won't be tested | |
* @return mixed Returns either the cached data or false | |
*/ | |
protected function _doFetch($id, $testCacheValidity = true) | |
{ | |
return parent::_doFetch($this->computeId($id), $testCacheValidity); | |
} | |
/** | |
* Test if a cache record exists for the passed id | |
* | |
* @param string $id cache id | |
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record | |
*/ | |
protected function _doContains($id) | |
{ | |
return parent::_doContains($this->computeId($id)); | |
} | |
/** | |
* Save a cache record directly. This method is implemented by the cache | |
* drivers and used in Doctrine_Cache_Driver::save() | |
* | |
* @param string $id cache id | |
* @param string $data data to cache | |
* @param int $lifeTime if != false, set a specific lifetime for this cache record (null => infinite lifeTime) | |
* @return boolean true if no problem | |
*/ | |
protected function _doSave($id, $data, $lifeTime = false) | |
{ | |
return parent::_doSave($this->computeId($id), $data, $lifeTime); | |
} | |
/** | |
* Remove a cache record directly. This method is implemented by the cache | |
* drivers and used in Doctrine_Cache_Driver::delete() | |
* | |
* @param string $id cache id | |
* @return boolean true if no problem | |
*/ | |
protected function _doDelete($id) | |
{ | |
return parent::_doDelete($this->computeId($id)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample usage, in case it's not clear: