From 90aa6e963d12eee2e287b61607caf0271384fbd8 Mon Sep 17 00:00:00 2001 From: Bout Date: Thu, 14 May 2020 10:00:35 +0200 Subject: [PATCH] Remove old cache references --- common/cache/class.Exception.php | 38 --- common/cache/class.FileCache.php | 40 --- common/cache/class.KeyValueCache.php | 133 ---------- common/cache/class.NoCache.php | 55 ---- common/cache/class.NotFoundException.php | 36 --- common/cache/class.PartitionedCachable.php | 265 -------------------- common/cache/class.PsrWrapperCache.php | 119 --------- common/cache/class.PurgeCache.php | 46 ---- common/cache/class.SingletonCache.php | 115 --------- common/cache/interface.Cache.php | 103 -------- config/default/cache.conf.php | 7 - scripts/update/Updater.php | 3 +- test/integration/common/cache/CacheTest.php | 62 ----- 13 files changed, 1 insertion(+), 1021 deletions(-) delete mode 100644 common/cache/class.Exception.php delete mode 100644 common/cache/class.FileCache.php delete mode 100644 common/cache/class.KeyValueCache.php delete mode 100644 common/cache/class.NoCache.php delete mode 100644 common/cache/class.NotFoundException.php delete mode 100644 common/cache/class.PartitionedCachable.php delete mode 100644 common/cache/class.PsrWrapperCache.php delete mode 100644 common/cache/class.PurgeCache.php delete mode 100755 common/cache/class.SingletonCache.php delete mode 100644 common/cache/interface.Cache.php delete mode 100644 config/default/cache.conf.php delete mode 100644 test/integration/common/cache/CacheTest.php diff --git a/common/cache/class.Exception.php b/common/cache/class.Exception.php deleted file mode 100644 index dbd4039ee..000000000 --- a/common/cache/class.Exception.php +++ /dev/null @@ -1,38 +0,0 @@ - - * @package generis - - */ -class common_cache_Exception extends common_Exception -{ - // --- ASSOCIATIONS --- - - - // --- ATTRIBUTES --- - - // --- OPERATIONS --- -} diff --git a/common/cache/class.FileCache.php b/common/cache/class.FileCache.php deleted file mode 100644 index 6940f9e95..000000000 --- a/common/cache/class.FileCache.php +++ /dev/null @@ -1,40 +0,0 @@ - - * @package generis - * @deprecated - */ -class common_cache_FileCache extends common_cache_KeyValueCache -{ - public static function singleton() - { - return ServiceManager::getServiceManager()->get('generis/cache'); - } -} diff --git a/common/cache/class.KeyValueCache.php b/common/cache/class.KeyValueCache.php deleted file mode 100644 index 2be66c0bb..000000000 --- a/common/cache/class.KeyValueCache.php +++ /dev/null @@ -1,133 +0,0 @@ - - * @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(); - } -} diff --git a/common/cache/class.NoCache.php b/common/cache/class.NoCache.php deleted file mode 100644 index a1c5c917d..000000000 --- a/common/cache/class.NoCache.php +++ /dev/null @@ -1,55 +0,0 @@ - - * @package generis - - */ -class common_cache_NotFoundException extends common_cache_Exception implements common_log_SeverityLevel -{ - public function getSeverity() - { - return common_Logger::DEBUG_LEVEL; - } -} diff --git a/common/cache/class.PartitionedCachable.php b/common/cache/class.PartitionedCachable.php deleted file mode 100644 index 39ea41e41..000000000 --- a/common/cache/class.PartitionedCachable.php +++ /dev/null @@ -1,265 +0,0 @@ - - * @package generis - - */ -abstract class common_cache_PartitionedCachable implements common_Serializable -{ - // --- ASSOCIATIONS --- - - - // --- ATTRIBUTES --- - - /** - * Short description of attribute serial - * - * @access protected - * @var string - */ - protected $serial = ''; - - /** - * Short description of attribute serializedProperties - * - * @access protected - * @var array - */ - protected $serializedProperties = []; - - // --- OPERATIONS --- - - /** - * Obtain a serial for the instance of the class that implements the - * - * @access public - * @author Jerome Bogaerts, - * @return string - */ - public function getSerial() - { - $returnValue = (string) ''; - - - if (empty($this->serial)) { - $this->serial = $this->buildSerial(); - } - $returnValue = $this->serial; - - - return (string) $returnValue; - } - - /** - * Short description of method __construct - * - * @access public - * @author Jerome Bogaerts, - * @return mixed - */ - public function __construct() - { - - if (!is_null($this->getCache())) { - $this->getCache()->put($this); - } - } - - /** - * Gives the list of attributes to serialize by reflection. - * - * @access public - * @author Jerome Bogaerts, - * @return array - */ - public function __sleep() - { - $returnValue = []; - - - $this->serializedProperties = []; - $reflection = new ReflectionClass($this); - foreach ($reflection->getProperties() as $property) { - //assuming that private properties don't contain serializables - if (!$property->isStatic() && !$property->isPrivate()) { - $propertyName = $property->getName(); - $containsSerializable = false; - $value = $this->$propertyName; - if (is_array($value)) { - $containsNonSerializable = false; - $serials = []; - foreach ($value as $key => $subvalue) { - if (is_object($subvalue) && $subvalue instanceof self) { - $containsSerializable = true; - $serials[$key] = $subvalue->getSerial(); - } else { - $containsNonSerializable = true; - } - } - if ($containsNonSerializable && $containsSerializable) { - throw new common_exception_Error('Serializable ' . $this->getSerial() . ' mixed serializable and non serializable values in property ' . $propertyName); - } - } else { - if (is_object($value) && $value instanceof self) { - $containsSerializable = true; - $serials = $value->getSerial(); - } - } - if ($containsSerializable) { - $this->serializedProperties[$property->getName()] = $serials; - } else { - $returnValue[] = $property->getName(); - } - } - } - - - return (array) $returnValue; - } - - /** - * Short description of method __wakeup - * - * @access public - * @author Jerome Bogaerts, - * @return mixed - */ - public function __wakeup() - { - - foreach ($this->serializedProperties as $key => $value) { - if (is_array($value)) { - $restored = []; - foreach ($value as $arrayKey => $arrayValue) { - $restored[$arrayKey] = $this->getCache()->get($arrayValue); - } - } else { - $restored = $this->getCache()->get($value); - } - $this->$key = $restored; - } - $this->serializedProperties = []; - } - - /** - * Short description of method _remove - * - * @access public - * @author Jerome Bogaerts, - * @return mixed - */ - public function _remove() - { - - //usefull only when persistance is enabled - if (!is_null($this->getCache())) { - //clean session - $this->getCache()->remove($this->getSerial()); - } - } - - /** - * Short description of method getSuccessors - * - * @access public - * @author Jerome Bogaerts, - * @return array - */ - public function getSuccessors() - { - $returnValue = []; - - - $reflection = new ReflectionClass($this); - foreach ($reflection->getProperties() as $property) { - if (!$property->isStatic() && !$property->isPrivate()) { - $propertyName = $property->getName(); - $value = $this->$propertyName; - if (is_array($value)) { - foreach ($value as $key => $subvalue) { - if (is_object($subvalue) && $subvalue instanceof self) { - $returnValue[] = $subvalue; - } - } - } elseif (is_object($value) && $value instanceof self) { - $returnValue[] = $value; - } - } - } - - - return (array) $returnValue; - } - - /** - * Short description of method getPredecessors - * - * @access public - * @author Jerome Bogaerts, - * @param string classFilter - * @return array - */ - public function getPredecessors($classFilter = null) - { - $returnValue = []; - - - foreach ($this->getCache()->getAll() as $serial => $instance) { - if ( - ($classFilter == null || $instance instanceof $classFilter) - && in_array($this, $instance->getSuccessors()) - ) { - $returnValue[] = $instance; - break; - } - } - - - return (array) $returnValue; - } - - /** - * Short description of method buildSerial - * - * @abstract - * @access protected - * @author Jerome Bogaerts, - * @return string - */ - abstract protected function buildSerial(); - - /** - * Short description of method getCache - * - * @abstract - * @access public - * @author Jerome Bogaerts, - * @return common_cache_Cache - */ - abstract public function getCache(); -} /* end of abstract class common_cache_PartitionedCachable */ diff --git a/common/cache/class.PsrWrapperCache.php b/common/cache/class.PsrWrapperCache.php deleted file mode 100644 index 3c2f212f9..000000000 --- a/common/cache/class.PsrWrapperCache.php +++ /dev/null @@ -1,119 +0,0 @@ - - * @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->getPsrSimpleCache()->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->getPsrSimpleCache()->get($serial, false); - if ($returnValue === false && !$this->getPsrSimpleCache()->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->getPsrSimpleCache()->has($serial); - } - - /** - * removes an entry from the cache - * - * @access public - * @author Jerome Bogaerts, - * @param string serial - * @return mixed - */ - public function remove($serial) - { - return $this->getPsrSimpleCache()->delete($serial); - } - - /** - * empties the cache - * - * @access public - * @author Jerome Bogaerts, - * @return mixed - */ - public function purge() - { - return $this->getPsrSimpleCache()->clear(); - } - - protected function getPsrSimpleCache() : CacheInterface - { - return $this->getServiceLocator()->get(SimpleCache::SERVICE_ID); - } -} diff --git a/common/cache/class.PurgeCache.php b/common/cache/class.PurgeCache.php deleted file mode 100644 index 18d57d72d..000000000 --- a/common/cache/class.PurgeCache.php +++ /dev/null @@ -1,46 +0,0 @@ -get('generis/cache')->purge(); - return $success - ? new common_report_Report(common_report_Report::TYPE_SUCCESS, 'Purged the filecache') - : new common_report_Report(common_report_Report::TYPE_ERROR, 'Cache could not be purged') - ; - } -} diff --git a/common/cache/class.SingletonCache.php b/common/cache/class.SingletonCache.php deleted file mode 100755 index 0a1dd76fd..000000000 --- a/common/cache/class.SingletonCache.php +++ /dev/null @@ -1,115 +0,0 @@ - - * @package generis - - */ -abstract class common_cache_SingletonCache -{ - // --- ASSOCIATIONS --- - - - // --- ATTRIBUTES --- - - /** - * Short description of attribute instances - * - * @access private - * @var array - */ - private static $instances = []; - - // --- OPERATIONS --- - - /** - * Short description of method singleton - * - * @access public - * @author Joel Bout, - * @return common_cache_Cache - */ - public static function singleton() - { - $returnValue = null; - - - $cacheName = get_called_class(); - if (!isset(self::$instances[$cacheName])) { - self::$instances[$cacheName] = new $cacheName(); - } - - $returnValue = self::$instances[$cacheName]; - - - return $returnValue; - } - - /** - * Short description of method getCached - * - * @access public - * @author Joel Bout, - * @param function - */ - public static function getCached($function) - { - $returnValue = null; - - - $args = func_get_args(); - array_shift($args); - if (!is_string($function)) { - $r = new ReflectionFunction($function); - $serial = md5( - $r->getFileName() . - $r->getStartLine() . - serialize($args) - ); - } else { - $serial = md5($function . serialize($args)); - } - if (static::singleton()->has($serial)) { - $returnValue = static::singleton()->has($serial); - } else { - $returnValue = call_user_func_array($fn, $args); - static::singleton()->put($serial, $returnValue); - } - - - return $returnValue; - } - - /** - * Short description of method __construct - * - * @access private - * @author Joel Bout, - * @return mixed - */ - private function __construct() - { - } -} /* end of abstract class common_cache_SingletonCache */ diff --git a/common/cache/interface.Cache.php b/common/cache/interface.Cache.php deleted file mode 100644 index b1b9c25de..000000000 --- a/common/cache/interface.Cache.php +++ /dev/null @@ -1,103 +0,0 @@ - - * @package generis - - */ - - -/** - * basic interface a cache implementation has to implement - * - * @access public - * @author Jerome Bogaerts, - * @package generis - - */ -interface common_cache_Cache -{ - /** - * Service manager id. - */ - const SERVICE_ID = 'generis/cache'; - - // --- OPERATIONS --- - - /** - * 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 mixed - */ - public function put($mixed, $serial = null, $ttl = null); - - /** - * gets the entry associted to the serial - * throws an exception if not found - * - * @access public - * @author Jerome Bogaerts, - * @param string serial - * @return common_Serializable - * @throws common_cache_NotFoundException - */ - public function get($serial); - - /** - * test whenever an entry associted to the serial exists - * - * @access public - * @author Jerome Bogaerts, - * @param string serial - * @return boolean - */ - public function has($serial); - - /** - * removes an entry from the cache - * - * @access public - * @author Jerome Bogaerts, - * @param string serial - * @return mixed - */ - public function remove($serial); - - /** - * empties the cache - * - * @access public - * @author Jerome Bogaerts, - * @return mixed - */ - public function purge(); -} diff --git a/config/default/cache.conf.php b/config/default/cache.conf.php deleted file mode 100644 index 6cbcf4da0..000000000 --- a/config/default/cache.conf.php +++ /dev/null @@ -1,7 +0,0 @@ -setOption( - \core_kernel_persistence_smoothsql_SmoothModel::OPTION_CACHE_SERVICE, - \common_cache_Cache::SERVICE_ID + \core_kernel_persistence_smoothsql_SmoothModel::OPTION_CACHE_SERVICE ); } $this->getServiceManager()->register(Ontology::SERVICE_ID, $ontologyModel); diff --git a/test/integration/common/cache/CacheTest.php b/test/integration/common/cache/CacheTest.php deleted file mode 100644 index 05ce14b68..000000000 --- a/test/integration/common/cache/CacheTest.php +++ /dev/null @@ -1,62 +0,0 @@ -assertFalse($cache->has($key)); - $this->assertTrue($cache->put('data', $key)); - $this->assertTrue($cache->has($key)); - $this->assertEquals('data', $cache->get($key)); - $this->assertTrue($cache->remove($key)); - $this->expectException(common_cache_NotFoundException::class); - $cache->get($key); - $this->assertFalse($cache->has($key)); - } - - - public function keyProvider() - { - return [ - ['normal'], - ['\' " {} \\ / and other strange chars : ~!@#$%^&*()_+?'], - ['_'], - [':'], - [' '], - [''] - ]; - } -}