Permalink
Browse files

Fixed some problems with the DoctrineAdapter and deletion.

Updated the CacheService definition to correctly normalize keys.
  • Loading branch information...
1 parent b91b4d0 commit 29869010c69d8a182a94a77494353fb53670080c @jhallbachner jhallbachner committed Sep 30, 2012
Showing with 47 additions and 8 deletions.
  1. +43 −4 Adapters/DoctrineAdapter.php
  2. +4 −4 Service/CacheService.php
@@ -9,29 +9,45 @@ class DoctrineAdapter implements DoctrineCacheInterface
{
protected $cacheService;
+ protected $namespace = '';
+
protected $caches = array();
public function __construct($cacheService)
{
$this->cacheService = $cacheService;
}
+ public function setNamespace($namespace)
+ {
+ $this->namespace = $namespace;
+ }
+
+ public function getNamespace()
+ {
+ return $this->namespace;
+ }
+
/**
* {@inheritDoc}
*/
public function fetch($id)
{
+ $id = $this->normalizeId($id);
+
if(isset($this->caches[$id])) {
$cache = $this->caches[$id];
unset($this->caches[$id]);
} else {
$cache = $this->cacheService->get($id);
}
+
+ $value = $cache->get();
if($cache->isMiss()) {
return false;
} else {
- return $cache->get();
+ return $value;
}
}
@@ -40,6 +56,8 @@ public function fetch($id)
*/
public function contains($id)
{
+ $id = $this->normalizeId($id);
+
$this->caches[$id] = $this->cacheService->get($id);
return $this->caches[$id]->isMiss();
@@ -50,6 +68,8 @@ public function contains($id)
*/
public function save($id, $data, $lifeTime = 0)
{
+ $id = $this->normalizeId($id);
+
$cache = $this->cacheService->get($id);
return $cache->set($data, $lifeTime);
@@ -60,8 +80,14 @@ public function save($id, $data, $lifeTime = 0)
*/
public function delete($id)
{
- $cache = $this->cacheService->get($id);
- return $cache->clear();
+ $id = $this->normalizeId($id);
+
+ return $this->cacheService->clear($id);
+ }
+
+ public function deleteAll()
+ {
+ return $this->flushAll();
}
/**
@@ -77,6 +103,19 @@ public function getStats()
return $stats;
}
+ public function flushAll()
+ {
+ $this->delete('');
+ }
-
+ protected function normalizeId($id)
+ {
+ if(isset($this->namespace)) {
+ $id = sprintf('zz_%s_zz/%s', $this->namespace, $id);
+ $id = trim($id, '/');
+ return $id;
+ } else {
+ return $id;
+ }
+ }
}
View
@@ -46,13 +46,13 @@ public function get()
$args = $args[0];
array_unshift($args, $this->key);
+ $key = join('/', $args);
$handler = (isset($this->handler)) ? $this->handler : null;
$cache = new StashCache($handler);
$stash = new CacheResultObject($cache, $this->logger);
- if(count($args) > 0)
- $stash->setupKey($args);
+ $stash->setupKey($key);
return $stash;
}
@@ -65,7 +65,7 @@ public function get()
*/
public function clear()
{
- $stash = $this->getCache(func_get_args());
+ $stash = $this->get(func_get_args());
return $stash->clear();
}
@@ -77,7 +77,7 @@ public function clear()
*/
public function purge()
{
- $stash = $this->getCache();
+ $stash = $this->get();
return $stash->purge();
}

0 comments on commit 2986901

Please sign in to comment.