diff options
author | Frédéric Guillot <fred@kanboard.net> | 2015-01-02 17:19:13 -0500 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2015-01-02 17:19:13 -0500 |
commit | 3076ba22dd8346725b4e1ad757532c00df5b18d9 (patch) | |
tree | e893c113c34d86c5dc923953754dc68c4b1d842d /app/Core/Cache.php | |
parent | c32567857db9bb1a6dfa339f58d817c97f64db11 (diff) |
Fix bugs, improve perfs and use SimpleLogger instead of Monolog
Diffstat (limited to 'app/Core/Cache.php')
-rw-r--r-- | app/Core/Cache.php | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/app/Core/Cache.php b/app/Core/Cache.php new file mode 100644 index 00000000..670a76e0 --- /dev/null +++ b/app/Core/Cache.php @@ -0,0 +1,58 @@ +<?php + +namespace Core; + +use Pimple\Container; + +abstract class Cache +{ + /** + * Container instance + * + * @access protected + * @var \Pimple\Container + */ + protected $container; + + abstract public function init(); + abstract public function set($key, $value); + abstract public function get($key); + abstract public function flush(); + abstract public function remove($key); + + /** + * Constructor + * + * @access public + * @param \Pimple\Container $container + */ + public function __construct(Container $container) + { + $this->container = $container; + $this->init(); + } + + /** + * Proxy cache + * + * Note: Arguments must be scalar types + * + * @access public + * @param string $container Container name + * @param string $method Container method + * @return mixed + */ + public function proxy($container, $method) + { + $args = func_get_args(); + $key = 'proxy_'.implode('_', $args); + $result = $this->get($key); + + if ($result === null) { + $result = call_user_func_array(array($this->container[$container], $method), array_splice($args, 2)); + $this->set($key, $result); + } + + return $result; + } +} |