Skip to content

Commit

Permalink
Fixes to comply with adapter-common 0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyholm committed Jan 19, 2016
1 parent fa9dbce commit 3191feb
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions src/MemcachedCachePool.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public function __construct(\Memcached $cache)

protected function fetchObjectFromCache($key)
{
return $this->cache->get($this->trimKey($this->getHierarchyKey($key)));
if (false === $result = unserialize($this->cache->get($this->getHierarchyKey($key)))) {
return [false, null];
}

return $result;
}

protected function clearAllObjectsFromCache()
Expand All @@ -51,8 +55,8 @@ protected function clearAllObjectsFromCache()
protected function clearOneObjectFromCache($key)
{
$this->commit();
$key = $this->trimKey($this->getHierarchyKey($key, $path));
$this->cache->increment($this->trimKey($path), 1, 0);
$key = $this->getHierarchyKey($key, $path);
$this->cache->increment($path, 1, 0);
$this->clearHierarchyKeyCache();

if ($this->cache->delete($key)) {
Expand All @@ -69,28 +73,13 @@ protected function storeItemInCache($key, CacheItemInterface $item, $ttl)
$ttl = 0;
}

$key = $this->trimKey($this->getHierarchyKey($key));
$key = $this->getHierarchyKey($key);

return $this->cache->set($key, $item, $ttl);
return $this->cache->set($key, serialize([true, $item->get()]), $ttl);
}

protected function getValueFormStore($key)
{
return $this->cache->get($this->trimKey($key));
}

/**
* Calculate a key. If it is more than 250 chars we should hash the key.
*
* @param $key
* @param null $ref
*/
private function trimKey($key)
{
if (strlen($key) < 250) {
return $key;
}
// This should maybe be logged
return sha1($key);
return $this->cache->get($key);
}
}

0 comments on commit 3191feb

Please sign in to comment.