Updating MemcacheEngine to use exceptions and implement missing CacheEngine methods.

This commit is contained in:
Mark Story 2010-04-18 00:46:19 -04:00
parent d7f16816e6
commit ca8110ad32

View file

@ -101,7 +101,7 @@ class MemcacheEngine extends CacheEngine {
* @param integer $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, &$value, $duration) {
public function write($key, $value, $duration) {
$expires = time() + $duration;
$this->__Memcache->set($key . '_expires', $expires, $this->settings['compress'], $expires);
return $this->__Memcache->set($key, $value, $this->settings['compress'], $expires);
@ -129,10 +129,13 @@ class MemcacheEngine extends CacheEngine {
* @param integer $offset How much to increment
* @param integer $duration How long to cache the data, in seconds
* @return New incremented value, false otherwise
* @throws RuntimeException when you try to increment with compress = true
*/
public function increment($key, $offset = 1) {
if ($this->settings['compress']) {
trigger_error(sprintf(__('Method increment() not implemented for compressed cache in %s'), get_class($this)), E_USER_ERROR);
throw new RuntimeException(
sprintf(__('Method increment() not implemented for compressed cache in %s'), __CLASS__)
);
}
return $this->__Memcache->increment($key, $offset);
}
@ -144,10 +147,13 @@ class MemcacheEngine extends CacheEngine {
* @param integer $offset How much to substract
* @param integer $duration How long to cache the data, in seconds
* @return New decremented value, false otherwise
* @throws RuntimeException when you try to decrement with compress = true
*/
public function decrement($key, $offset = 1) {
if ($this->settings['compress']) {
trigger_error(sprintf(__('Method decrement() not implemented for compressed cache in %s'), get_class($this)), E_USER_ERROR);
throw new RuntimeException(
sprintf(__('Method decrement() not implemented for compressed cache in %s'), __CLASS__)
);
}
return $this->__Memcache->decrement($key, $offset);
}
@ -167,10 +173,20 @@ class MemcacheEngine extends CacheEngine {
*
* @return boolean True if the cache was succesfully cleared, false otherwise
*/
public function clear() {
public function clear($check) {
return $this->__Memcache->flush();
}
/**
* Not implemented - Memcache does not provide a native way to do garbage collection
*
* @return void
* @throws BadMethodCallException
*/
public function gc() {
throw new BadMethodCallException(__('Cannot gc() with Memcache.'));
}
/**
* Connects to a server in connection pool
*