diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-08-21 18:46:34 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-08-21 18:46:34 -0400 |
commit | 8e83e404fbb1d0dc770e5b41fa315a674541459a (patch) | |
tree | 38186a4ef5818133489b41f85f200fa28bed2806 /app/Core/Cache/BaseCache.php | |
parent | 836e93546355e20f5a3cca0e2fd4e649264ce7ac (diff) |
Add FileCache driver
Diffstat (limited to 'app/Core/Cache/BaseCache.php')
-rw-r--r-- | app/Core/Cache/BaseCache.php | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/app/Core/Cache/BaseCache.php b/app/Core/Cache/BaseCache.php new file mode 100644 index 00000000..04f8d220 --- /dev/null +++ b/app/Core/Cache/BaseCache.php @@ -0,0 +1,71 @@ +<?php + +namespace Kanboard\Core\Cache; + +/** + * Base Class for Cache Drivers + * + * @package Kanboard\Core\Cache + * @author Frederic Guillot + */ +abstract class BaseCache +{ + /** + * Store an item in the cache + * + * @access public + * @param string $key + * @param string $value + */ + abstract public function set($key, $value); + + /** + * Retrieve an item from the cache by key + * + * @access public + * @param string $key + * @return mixed Null when not found, cached value otherwise + */ + abstract public function get($key); + + /** + * Remove all items from the cache + * + * @access public + */ + abstract public function flush(); + + /** + * Remove an item from the cache + * + * @access public + * @param string $key + */ + abstract public function remove($key); + + /** + * Proxy cache + * + * Note: Arguments must be scalar types + * + * @access public + * @param string $class Class instance + * @param string $method Container method + * @return mixed + */ + public function proxy($class, $method) + { + $args = func_get_args(); + array_shift($args); + + $key = 'proxy:'.get_class($class).':'.implode(':', $args); + $result = $this->get($key); + + if ($result === null) { + $result = call_user_func_array(array($class, $method), array_splice($args, 1)); + $this->set($key, $result); + } + + return $result; + } +} |