Skip to content

Commit

Permalink
[mms] Hashtable driver now respects lifetime parameter in the get() a…
Browse files Browse the repository at this point in the history
…nd exists() methods (Bug #13085).
  • Loading branch information
slusarz committed Apr 1, 2014
1 parent 6206380 commit 426cfe7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
36 changes: 27 additions & 9 deletions framework/Cache/lib/Horde/Cache/Storage/Hashtable.php
Expand Up @@ -57,35 +57,52 @@ protected function _initOb()
}

/**
* NOTE: This driver ignores the lifetime argument.
*/
public function get($key, $lifetime = 0)
{
return $this->_hash->get($this->_getKey($key));
$dkey = $this->_getKey($key);
$query = array($dkey);
if ($lifetime) {
$query[] = $lkey = $this->_getKey($key, true);
}

$res = $this->_hash->get($query);

if ($lifetime &&
(!$res[$lkey] || (($lifetime + $res[$lkey]) < time()))) {
return false;
}

return $res[$dkey];
}

/**
*/
public function set($key, $data, $lifetime = 0)
{
$this->_hash->set($this->_getKey($key), $data, array_filter(array(
$opts = array_filter(array(
'expire' => $lifetime
)));
));

$this->_hash->set($this->_getKey($key), $data, $opts);
$this->_hash->set($this->_getKey($key, true), time(), $opts);
}

/**
* NOTE: This driver ignores the lifetime argument.
*/
public function exists($key, $lifetime = 0)
{
return $this->_hash->exists($this->_getKey($key));
return ($this->get($key, $lifetime) !== false);
}

/**
*/
public function expire($key)
{
$this->_hash->delete($this->_getKey($key));
$this->_hash->delete(array(
$this->_getKey($key),
$this->_getKey($key, true)
));
}

/**
Expand All @@ -99,12 +116,13 @@ public function clear()
* Return the hashtable key.
*
* @param string $key Object ID.
* @param boolean $ts Return the timestamp key?
*
* @return string Hashtable key ID.
*/
protected function _getKey($key)
protected function _getKey($key, $ts = false)
{
return $this->_params['prefix'] . $key;
return $this->_params['prefix'] . $key . ($ts ? '_t' : '');
}

}
4 changes: 2 additions & 2 deletions framework/Cache/package.xml
Expand Up @@ -27,7 +27,7 @@
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [mms] Hashtable driver now respects lifetime parameter in the get() and exists() methods (Bug #13085).
</notes>
<contents>
<dir baseinstalldir="/" name="/">
Expand Down Expand Up @@ -559,7 +559,7 @@ Initial packaging.
<date>2014-02-11</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [mms] Hashtable driver now respects lifetime parameter in the get() and exists() methods (Bug #13085).
</notes>
</release>
</changelog>
Expand Down

0 comments on commit 426cfe7

Please sign in to comment.