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/MemoryCache.php | |
parent | 8079b5af64fbebd14a3a0e470bc48bcb4a9bade3 (diff) |
Add abstract cache layer
Diffstat (limited to 'app/Core/Cache/MemoryCache.php')
-rw-r--r-- | app/Core/Cache/MemoryCache.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/app/Core/Cache/MemoryCache.php b/app/Core/Cache/MemoryCache.php new file mode 100644 index 00000000..b1de96bc --- /dev/null +++ b/app/Core/Cache/MemoryCache.php @@ -0,0 +1,65 @@ +<?php + +namespace Core\Cache; + +/** + * Memory Cache + * + * @package cache + * @author Frederic Guillot + */ +class MemoryCache extends Base implements CacheInterface +{ + /** + * Container + * + * @access private + * @var array + */ + private $storage = array(); + + /** + * Save a new value in the cache + * + * @access public + * @param string $key + * @param string $value + */ + public function set($key, $value) + { + $this->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]); + } +} |