Skip to content

Commit

Permalink
Making CacheEngine an abstract class, and updating FileEngine to incl…
Browse files Browse the repository at this point in the history
…ude the not implemented methods.
  • Loading branch information
markstory committed Apr 18, 2010
1 parent 92215e1 commit a886e13
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
33 changes: 12 additions & 21 deletions cake/libs/cache.php
Expand Up @@ -486,7 +486,7 @@ public static function settings($name = null) {
* @package cake
* @subpackage cake.cake.libs
*/
class CacheEngine {
abstract class CacheEngine {

/**
* Settings of current engine instance
Expand Down Expand Up @@ -520,32 +520,27 @@ public function init($settings = array()) {
* 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
*
* @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
Expand All @@ -554,36 +549,32 @@ public function read($key) {
* @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
*
* @param string $key Identifier for the data
* @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
*
* @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
Expand Down
22 changes: 21 additions & 1 deletion cake/libs/cache/file.php
Expand Up @@ -110,7 +110,7 @@ public function gc() {
* @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;
}
Expand Down Expand Up @@ -227,6 +227,26 @@ public function clear($check) {
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
*
Expand Down

0 comments on commit a886e13

Please sign in to comment.