* @package generis * @deprecated Please use oat\oatbox\cache\SimpleCache */ class common_cache_KeyValueCache extends ConfigurableService implements common_cache_Cache { const OPTION_PERSISTENCE = 'persistence'; /** * @var common_persistence_KeyValuePersistence */ private $persistence; protected function getPersistence() { if (is_null($this->persistence)) { $this->persistence = $this->getServiceLocator()->get('generis/persistences')->getPersistenceById($this->getOption(self::OPTION_PERSISTENCE)); } return $this->persistence; } /** * puts "something" into the cache, * * If this is an object and implements Serializable, * * we use the serial provided by the object * * else a serial must be provided * @access public * @author Jerome Bogaerts, * @param mixed $mixed * @param null $serial * @param null $ttl * @return bool * @throws common_exception_Error */ public function put($mixed, $serial = null, $ttl = null) { if ($mixed instanceof common_Serializable) { if (!is_null($serial) && $serial != $mixed->getSerial()) { throw new common_exception_Error('Serial mismatch for Serializable ' . $mixed->getSerial()); } $serial = $mixed->getSerial(); } return $this->getPersistence()->set($serial, $mixed, $ttl); } /** * gets the entry associted to the serial * * @access public * @author Jerome Bogaerts, * @param string serial * @return common_Serializable * @throws common_cache_NotFoundException */ public function get($serial) { $returnValue = $this->getPersistence()->get($serial); if ($returnValue === false && !$this->has($serial)) { $msg = "No cache entry found for '" . $serial . "'."; throw new common_cache_NotFoundException($msg); } return $returnValue; } /** * test whenever an entry associated to the serial exists * * @access public * @author Jerome Bogaerts, * @param string serial * @return boolean */ public function has($serial) { return $this->getPersistence()->exists($serial); } /** * removes an entry from the cache * * @access public * @author Jerome Bogaerts, * @param string serial * @return mixed */ public function remove($serial) { return $this->getPersistence()->del($serial); } /** * empties the cache * * @access public * @author Jerome Bogaerts, * @return mixed */ public function purge() { return $this->getPersistence()->purge(); } }