From fe57edd9e87832dbd14ea8ffd2dc2f16ac1ceb6f Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 20 Sep 2015 12:38:35 -0400 Subject: Add abstract cache layer --- app/Core/Cache/Base.php | 38 +++++++++++++++++++++++ app/Core/Cache/CacheInterface.php | 45 +++++++++++++++++++++++++++ app/Core/Cache/MemoryCache.php | 65 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 app/Core/Cache/Base.php create mode 100644 app/Core/Cache/CacheInterface.php create mode 100644 app/Core/Cache/MemoryCache.php (limited to 'app/Core/Cache') 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 @@ +get($key); + + if ($result === null) { + $result = call_user_func_array(array($class, $method), array_splice($args, 1)); + $this->set($key, $result); + } + + return $result; + } +} diff --git a/app/Core/Cache/CacheInterface.php b/app/Core/Cache/CacheInterface.php new file mode 100644 index 00000000..8675ef8e --- /dev/null +++ b/app/Core/Cache/CacheInterface.php @@ -0,0 +1,45 @@ +storage[$key] = $value; + } + + /** + * Fetch value from cache + * + * @access public + * @param string $key + * @return mixed Null when not found, cached value otherwise + */ + public function get($key) + { + return isset($this->storage[$key]) ? $this->storage[$key] : null; + } + + /** + * Clear all cache + * + * @access public + */ + public function flush() + { + $this->storage = array(); + } + + /** + * Remove cached value + * + * @access public + * @param string $key + */ + public function remove($key) + { + unset($this->storage[$key]); + } +} -- cgit v1.2.3