diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-09-20 12:38:35 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-09-20 12:38:35 -0400 |
commit | fe57edd9e87832dbd14ea8ffd2dc2f16ac1ceb6f (patch) | |
tree | b8124f61496c9ce6d0d805e83e2818c6746711f9 /app/Core/Cache/Base.php | |
parent | 8079b5af64fbebd14a3a0e470bc48bcb4a9bade3 (diff) |
Add abstract cache layer
Diffstat (limited to 'app/Core/Cache/Base.php')
-rw-r--r-- | app/Core/Cache/Base.php | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/app/Core/Cache/Base.php b/app/Core/Cache/Base.php new file mode 100644 index 00000000..a16c12f0 --- /dev/null +++ b/app/Core/Cache/Base.php @@ -0,0 +1,38 @@ +<?php + +namespace Core\Cache; + +/** + * Base class for cache drivers + * + * @package cache + * @author Frederic Guillot + */ +abstract class Base +{ + /** + * 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; + } +} |