diff options
Diffstat (limited to 'public/system/library/cache.php')
-rw-r--r-- | public/system/library/cache.php | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/public/system/library/cache.php b/public/system/library/cache.php new file mode 100644 index 0000000..d0aa5a7 --- /dev/null +++ b/public/system/library/cache.php @@ -0,0 +1,64 @@ +<?php +/** + * @package OpenCart + * @author Daniel Kerr + * @copyright Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/) + * @license https://opensource.org/licenses/GPL-3.0 + * @link https://www.opencart.com +*/ + +/** +* Cache class +*/ +class Cache { + private $adaptor; + + /** + * Constructor + * + * @param string $adaptor The type of storage for the cache. + * @param int $expire Optional parameters + * + */ + public function __construct($adaptor, $expire = 3600) { + $class = 'Cache\\' . $adaptor; + + if (class_exists($class)) { + $this->adaptor = new $class($expire); + } else { + throw new \Exception('Error: Could not load cache adaptor ' . $adaptor . ' cache!'); + } + } + + /** + * Gets a cache by key name. + * + * @param string $key The cache key name + * + * @return string + */ + public function get($key) { + return $this->adaptor->get($key); + } + + /** + * + * + * @param string $key The cache key + * @param string $value The cache value + * + * @return string + */ + public function set($key, $value) { + return $this->adaptor->set($key, $value); + } + + /** + * + * + * @param string $key The cache key + */ + public function delete($key) { + return $this->adaptor->delete($key); + } +} |