Permalink
Browse files

Implement ZF1 Memcached::increment

  • Loading branch information...
tefra committed Dec 15, 2013
1 parent 395b087 commit 10973f585569474850f8f315b0a0e14c69444e8f
Showing with 32 additions and 0 deletions.
  1. +32 −0 library/Zend/Cache/Backend/Memcached.php
@@ -475,6 +475,38 @@ public function touch($id, $extraLifetime)
return false;
}
/**
* Memcached::increment
*
* @param string $id cache id
* @param numerical $offset to increase counter
* @param numerical $initial value to set counter
* @param int $extraLifetime
* @return numerical new items value on success or FALSE on failure.
*/
public function increment($id, $offset = 1, $initial = 0, $specificLifetime = false)
{
$result = $this->_memcache->increment($id, $offset);
if (!$result) {
$lifetime = $this->getLifetime($specificLifetime);
$this->_memcache->add($id, $initial, false, $lifetime);
$result = $this->_memcache->increment($id, $offset);
}
return $result;
}
/**
* Custom get to retrieve incremental items
*
* @param string $id cache id
* @return numerical|false cached item
*/
public function getCounterKey($id)
{
$tmp = $this->_memcache->get($id);
return is_numeric($tmp) ? $tmp : false;
}
/**
* Return an associative array of capabilities (booleans) of the backend
*

0 comments on commit 10973f5

Please sign in to comment.