diff --git a/ApplicationAbstract.php b/ApplicationAbstract.php index d99810590..6e4d3f3d1 100644 --- a/ApplicationAbstract.php +++ b/ApplicationAbstract.php @@ -64,10 +64,10 @@ class ApplicationAbstract /** * Cache instance. * - * @var \phpOMS\DataStorage\Cache\CacheManager + * @var \phpOMS\DataStorage\Cache\Pool * @since 1.0.0 */ - public $cacheManager = null; + public $cachePool = null; /** * ModuleManager instance. diff --git a/DataStorage/Cache/CacheManager.php b/DataStorage/Cache/CacheManager.php deleted file mode 100644 index d72f7677d..000000000 --- a/DataStorage/Cache/CacheManager.php +++ /dev/null @@ -1,248 +0,0 @@ - - * @author Dennis Eichhorn - * @copyright 2013 Dennis Eichhorn - * @license OMS License 1.0 - * @version 1.0.0 - * @link http://orange-management.com - */ -namespace phpOMS\DataStorage\Cache; - -use phpOMS\Config\OptionsInterface; -use phpOMS\Config\OptionsTrait; - - -use phpOMS\DataStorage\Database\Pool; - -/** - * Cache class. - * - * Responsible for caching scalar data types and arrays. - * Caching HTML output and objects coming soon/is planned. - * - * @category Framework - * @package phpOMS\DataStorage\Cache - * @author OMS Development Team - * @author Dennis Eichhorn - * @license OMS License 1.0 - * @link http://orange-management.com - * @since 1.0.0 - */ -class CacheManager implements OptionsInterface -{ - use OptionsTrait; - - /** - * MemCache instance. - * - * @var \phpOMS\DataStorage\Cache\MemCache - * @since 1.0.0 - */ - private $memc = null; - - /** - * RedisCache instance. - * - * @var \phpOMS\DataStorage\Cache\RedisCache - * @since 1.0.0 - */ - private $redisc = null; - - /** - * RedisCache instance. - * - * @var \phpOMS\DataStorage\Cache\WinCache - * @since 1.0.0 - */ - private $winc = null; - - /** - * FileCache instance. - * - * @var \phpOMS\DataStorage\Cache\FileCache - * @since 1.0.0 - */ - private $filec = null; - - /** - * FileCache instance. - * - * @var Pool - * @since 1.0.0 - */ - private $dbPool = null; - - /** - * Constructor. - * - * @param Pool $dbPool Database pool - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - public function __construct(Pool $dbPool) - { - $this->dbPool = $dbPool; - } - - /** - * Init cache. - * - * @param mixed $options Options used to initialize the different caching types - * - * @return void - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - public function init($options = null) - { - if ($options === null) { - /* This is costing me 1ms, maybe init settings first cause i'm making another settings call later on -> same call 2 times */ - $sth = $this->dbPool->get('core')->con->prepare('SELECT `content` FROM `' . $this->dbPool->get('core')->prefix . 'settings` WHERE `id` = 1000000015'); - $sth->execute(); - $cache_data = $sth->fetchAll(); - - $this->setOption('cache:type', (int) $cache_data[0][0]); - } else { - $this->options = $options; - } - } - - /** - * {@inheritdoc} - */ - public function update() - { - } - - /** - * {@inheritdoc} - */ - public function set($key, $value, CacheStatus $type = null, \int $expire = 2592000) - { - $this->getInstance($type)->set($key, $value, $type = null, $expire); - } - - /** - * Requesting caching instance. - * - * @param CacheStatus $type Cache to request - * - * @return \phpOMS\DataStorage\Cache\MemCache|\phpOMS\DataStorage\Cache\FileCache|null - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - public function getInstance(CacheStatus $type = null) - { - if (($type === null || $type === CacheStatus::MEMCACHE) && $this->memc !== null) { - return $this->memc; - } - - if (($type === null || $type === CacheStatus::REDISCACHE) && $this->redisc !== null) { - return $this->redisc; - } - - if (($type === null || $type === CacheStatus::WINCACHE) && $this->winc !== null) { - return $this->winc; - } - - if (($type === null || $type === CacheStatus::FILECACHE) && $this->filec !== null) { - return $this->filec; - } - - return new NullCache(); - } - - /** - * {@inheritdoc} - */ - public function add($key, $value, CacheStatus $type = null, \int $expire = 2592000) - { - $this->getInstance($type)->add($key, $value, $type = null, $expire); - } - - /** - * {@inheritdoc} - */ - public function get($key, CacheStatus $type = null) - { - return $this->getInstance($type)->get($key); - } - - /** - * {@inheritdoc} - */ - public function delete($key, CacheStatus $type = null) - { - $this->getInstance($type)->delete($key); - } - - /** - * {@inheritdoc} - */ - public function flush(CacheStatus $type = null) - { - if ($type === null) { - $this->filec->flush(); - $this->memc->flush(); - } elseif ($type === CacheStatus::MEMCACHE) { - $this->memc->flush(); - } elseif ($type === CacheStatus::FILECACHE) { - $this->filec->flush(); - } - } - - /** - * {@inheritdoc} - */ - public function replace($key, $value, CacheType $type = null) - { - $this->getInstance($type)->replace($key, $value); - } - - /** - * {@inheritdoc} - */ - public function stats() : array - { - $stats = []; - - if ($this->memc !== null) { - $stats['memc'] = $this->memc->stats(); - } - - if ($this->filec !== null) { - $stats['filec'] = $this->filec->stats(); - } - - return $stats; - } - - /** - * {@inheritdoc} - */ - public function getThreshold() : array - { - $threshold = []; - - if ($this->memc !== null) { - $threshold['memc'] = $this->memc->getThreshold(); - } - - if ($this->filec !== null) { - $threshold['filec'] = $this->filec->getThreshold(); - } - - return $threshold; - } - -} diff --git a/DataStorage/Cache/Pool.php b/DataStorage/Cache/Pool.php new file mode 100644 index 000000000..dc1b530c3 --- /dev/null +++ b/DataStorage/Cache/Pool.php @@ -0,0 +1,131 @@ + + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace phpOMS\DataStorage\Cache; + +use phpOMS\Config\OptionsInterface; +use phpOMS\Config\OptionsTrait; + + +/** + * Cache class. + * + * Responsible for caching scalar data types and arrays. + * Caching HTML output and objects coming soon/is planned. + * + * @category Framework + * @package phpOMS\DataStorage\Cache + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Pool implements OptionsInterface +{ + use OptionsTrait; + + /** + * MemCache instance. + * + * @var \phpOMS\DataStorage\Cache\MemCache + * @since 1.0.0 + */ + private $memc = null; + + /** + * RedisCache instance. + * + * @var \phpOMS\DataStorage\Cache\RedisCache + * @since 1.0.0 + */ + private $redisc = null; + + /** + * RedisCache instance. + * + * @var \phpOMS\DataStorage\Cache\WinCache + * @since 1.0.0 + */ + private $winc = null; + + /** + * FileCache instance. + * + * @var \phpOMS\DataStorage\Cache\FileCache + * @since 1.0.0 + */ + private $filec = null; + + + /** + * Constructor. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function __construct() + { + } + + /** + * Requesting caching instance. + * + * @param \int $type Cache to request + * + * @return \phpOMS\DataStorage\Cache\MemCache|\phpOMS\DataStorage\Cache\FileCache|null + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function get(\int $type = null) + { + if (($type === null || $type === CacheStatus::MEMCACHE) && $this->memc !== null) { + return $this->memc; + } + + if (($type === null || $type === CacheStatus::REDISCACHE) && $this->redisc !== null) { + return $this->redisc; + } + + if (($type === null || $type === CacheStatus::WINCACHE) && $this->winc !== null) { + return $this->winc; + } + + if (($type === null || $type === CacheStatus::FILECACHE) && $this->filec !== null) { + return $this->filec; + } + + return new NullCache(); + } + + /** + * {@inheritdoc} + */ + public function add(\int $type, CacheInterface $cache) + { + if (($type === null || $type === CacheStatus::MEMCACHE) && $this->memc !== null) { + $this->memc = $cache; + } elseif (($type === null || $type === CacheStatus::REDISCACHE) && $this->redisc !== null) { + $this->redisc = $cache; + } elseif (($type === null || $type === CacheStatus::WINCACHE) && $this->winc !== null) { + $this->winc = $cache; + } elseif (($type === null || $type === CacheStatus::FILECACHE) && $this->filec !== null) { + $this->filec = $cache; + } else { + throw new \Exception('Invalid type'); + } + } +}