Permalink
Browse files

add incrementBy and derementBy method in all cache driver

  • Loading branch information...
1 parent edce928 commit bfc3cc4e49b63197ec58f0166067538233f1dd92 @ikandars ikandars committed May 2, 2012
@@ -120,6 +120,28 @@ public function flushValues(){
return apc_clear_cache('user');
}
+ /**
+ * Increment numeric item's value
+ *
+ * @param string $key The key of the item
+ * @param int $offset The amount by which to increment the item's value
+ */
+ public function incrementBy($key, $offset = 1){
+
+ return apc_inc($key, $offset);
+ }
+
+ /**
+ * Decrement numeric item's value
+ *
+ * @param string $key The key of the item
+ * @param int $offset The amount by which to decrement the item's value
+ */
+ public function decrementBy($key, $offset = 1){
+
+ return apc_dec($key, $offset);
+ }
+
/**
* Namespace usefull when we need to wildcard deleting cache object.
*
@@ -121,4 +121,34 @@ public static function _flush(){
unset(self::$holder);
return true;
}
+
+ /**
+ * Increment numeric item's value
+ *
+ * @param string $key The key of the item
+ * @param int $offset The amount by which to increment the item's value
+ */
+ public function incrementBy($key, $offset = 1){
+
+ $incr = $this->getValue($key) + $offset;
+
+ $this->updateValue($key, $incr);
+
+ return $incr;
+ }
+
+ /**
+ * Decrement numeric item's value
+ *
+ * @param string $key The key of the item
+ * @param int $offset The amount by which to decrement the item's value
+ */
+ public function decrementBy($key, $offset = 1){
+
+ $decr = $this->getValue($key) - $offset;
+
+ $this->updateValue($key, $decr);
+
+ return $decr;
+ }
}
@@ -114,6 +114,28 @@ public function flushValues(){
return $this->flush();
}
+ /**
+ * Increment numeric item's value
+ *
+ * @param string $key The key of the item
+ * @param int $offset The amount by which to increment the item's value
+ */
+ public function incrementBy($key, $offset = 1){
+
+ return $this->increment($key, $offset);
+ }
+
+ /**
+ * Decrement numeric item's value
+ *
+ * @param string $key The key of the item
+ * @param int $offset The amount by which to decrement the item's value
+ */
+ public function decrementBy($key, $offset = 1){
+
+ return $this->decrement($key, $offset);
+ }
+
/**
* Namespace usefull when we need to wildcard deleting cache object.
*
@@ -104,6 +104,28 @@ public function flushValues(){
return $this->flush();
}
+ /**
+ * Increment numeric item's value
+ *
+ * @param string $key The key of the item
+ * @param int $offset The amount by which to increment the item's value
+ */
+ public function incrementBy($key, $offset = 1){
+
+ return $this->increment($key, $offset);
+ }
+
+ /**
+ * Decrement numeric item's value
+ *
+ * @param string $key The key of the item
+ * @param int $offset The amount by which to decrement the item's value
+ */
+ public function decrementBy($key, $offset = 1){
+
+ return $this->decrement($key, $offset);
+ }
+
/**
* Namespace usefull when we need to wildcard deleting cache object.
*
@@ -113,6 +113,28 @@ public function flushValues(){
return $this->flushDB();
}
+ /**
+ * Increment numeric item's value
+ *
+ * @param string $key The key of the item
+ * @param int $offset The amount by which to increment the item's value
+ */
+ public function incrementBy($key, $offset = 1){
+
+ return $this->incr($key, $offset);
+ }
+
+ /**
+ * Decrement numeric item's value
+ *
+ * @param string $key The key of the item
+ * @param int $offset The amount by which to decrement the item's value
+ */
+ public function decrementBy($key, $offset = 1){
+
+ return $this->decr($key, $offset);
+ }
+
/**
* Namespace usefull when we need to wildcard deleting cache object.
*
@@ -18,4 +18,6 @@ public function updateValue( $key, $value, $expire = 0, $namespace = false );
public function getValue( $key, $namespace = false );
public function deleteValue( $key, $namespace = false );
public function flushValues();
+ public function incrementBy($key, $offset = 1);
+ public function decrementBy($key, $offset = 1);
}

0 comments on commit bfc3cc4

Please sign in to comment.