From a886e1366639ce54754e49a0577c74631513ab2b Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sun, 18 Apr 2010 00:38:36 -0400 Subject: [PATCH] Making CacheEngine an abstract class, and updating FileEngine to include the not implemented methods. --- cake/libs/cache.php | 33 ++++++++++++--------------------- cake/libs/cache/file.php | 22 +++++++++++++++++++++- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/cake/libs/cache.php b/cake/libs/cache.php index c4c769a26..2e6694a97 100644 --- a/cake/libs/cache.php +++ b/cake/libs/cache.php @@ -486,7 +486,7 @@ class Cache { * @package cake * @subpackage cake.cake.libs */ -class CacheEngine { +abstract class CacheEngine { /** * Settings of current engine instance @@ -520,22 +520,19 @@ class CacheEngine { * Garbage collection * * Permanently remove all expired and deleted data - * + * @return void */ - public function gc() { - } + abstract public function gc(); /** * Write value for a key into cache * * @param string $key Identifier for the data * @param mixed $value Data to be cached - * @param mixed $duration How long to cache the data, in seconds + * @param mixed $duration How long to cache for. * @return boolean True if the data was succesfully cached, false on failure */ - public function write($key, &$value, $duration) { - trigger_error(sprintf(__('Method write() not implemented in %s'), get_class($this)), E_USER_ERROR); - } + abstract public function write($key, $value, $duration); /** * Read a key from the cache @@ -543,9 +540,7 @@ class CacheEngine { * @param string $key Identifier for the data * @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it */ - public function read($key) { - trigger_error(sprintf(__('Method read() not implemented in %s'), get_class($this)), E_USER_ERROR); - } + abstract public function read($key); /** * Increment a number under the key and return incremented value @@ -554,9 +549,8 @@ class CacheEngine { * @param integer $offset How much to add * @return New incremented value, false otherwise */ - public function increment($key, $offset = 1) { - trigger_error(sprintf(__('Method increment() not implemented in %s'), get_class($this)), E_USER_ERROR); - } + abstract public function increment($key, $offset = 1); + /** * Decrement a number under the key and return decremented value * @@ -564,17 +558,15 @@ class CacheEngine { * @param integer $value How much to substract * @return New incremented value, false otherwise */ - public function decrement($key, $offset = 1) { - trigger_error(sprintf(__('Method decrement() not implemented in %s'), get_class($this)), E_USER_ERROR); - } + abstract public function decrement($key, $offset = 1); + /** * Delete a key from the cache * * @param string $key Identifier for the data * @return boolean True if the value was succesfully deleted, false if it didn't exist or couldn't be removed */ - public function delete($key) { - } + abstract public function delete($key); /** * Delete all keys from the cache @@ -582,8 +574,7 @@ class CacheEngine { * @param boolean $check if true will check expiration, otherwise delete all * @return boolean True if the cache was succesfully cleared, false otherwise */ - public function clear($check) { - } + abstract public function clear($check); /** * Cache Engine settings diff --git a/cake/libs/cache/file.php b/cake/libs/cache/file.php index c56e94dd4..23fe3490a 100644 --- a/cake/libs/cache/file.php +++ b/cake/libs/cache/file.php @@ -110,7 +110,7 @@ class FileEngine extends CacheEngine { * @param mixed $duration How long to cache the data, in seconds * @return boolean True if the data was succesfully cached, false on failure */ - public function write($key, &$data, $duration) { + public function write($key, $data, $duration) { if ($data === '' || !$this->_init) { return false; } @@ -227,6 +227,26 @@ class FileEngine extends CacheEngine { return true; } +/** + * Not implemented + * + * @return void + * @throws BadMethodCallException + */ + public function decrement($key, $offset = 1) { + throw new BadMethodCallException('Files cannot be atomically decremented.'); + } + +/** + * Not implemented + * + * @return void + * @throws BadMethodCallException + */ + public function increment($key, $offset = 1) { + throw new BadMethodCallException('Files cannot be atomically incremented.'); + } + /** * Get absolute file for a given key *