Index: Core.php =================================================================== --- Core.php (revision 7970) +++ Core.php (working copy) @@ -51,6 +51,9 @@ * - Enable / disable caching * (can be very usefull for the debug of cached scripts) * + * =====> (string) cache_id_prefix : + * prefix for cache ids + * * ====> (boolean) automatic_serialization : * - Enable / disable automatic serialization * - It can be used to save directly datas which aren't strings (but it's slower) @@ -79,6 +82,7 @@ protected $_options = array( 'write_control' => true, 'caching' => true, + 'cache_id_prefix' => null, 'automatic_serialization' => false, 'automatic_cleaning_factor' => 10, 'lifetime' => 3600, @@ -212,6 +216,7 @@ if (!$this->_options['caching']) { return false; } + $id = $this->_id($id); // cache id may need prefix $this->_lastId = $id; self::_validateIdOrTag($id); $data = $this->_backend->load($id, $doNotTestCacheValidity); @@ -237,6 +242,7 @@ if (!$this->_options['caching']) { return false; } + $id = $this->_id($id); // cache id may need prefix self::_validateIdOrTag($id); $this->_lastId = $id; return $this->_backend->test($id); @@ -258,6 +264,8 @@ } if (is_null($id)) { $id = $this->_lastId; + } else { + $id = $this->_id($id); } self::_validateIdOrTag($id); self::_validateTagsArray($tags); @@ -317,6 +325,7 @@ if (!$this->_options['caching']) { return true; } + $id = $this->_id($id); // cache id may need prefix self::_validateIdOrTag($id); return $this->_backend->remove($id); } @@ -437,4 +446,20 @@ $logger->log($message, $priority); } + /** + * Make and return a cache id + * + * Checks 'cache_id_prefix' and returns new id with prefix or simply the id if null + * + * @param string $id cache id + * @return string cache id (with or without prefix) + */ + private function _id($id) + { + if (!is_null($id) && isset($this->_options['cache_id_prefix'])) { + return $this->_options['cache_id_prefix'] . $id; // return with prefix + } + return $id; // no prefix, just return the $id passed + } + }