Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed some problems with the DoctrineAdapter and deletion.

Updated the CacheService definition to correctly normalize keys.
  • Loading branch information...
commit 29869010c69d8a182a94a77494353fb53670080c 1 parent b91b4d0
Josh Hall-Bachner authored

Showing 2 changed files with 47 additions and 8 deletions. Show diff stats Hide diff stats

  1. +43 4 Adapters/DoctrineAdapter.php
  2. +4 4 Service/CacheService.php
47 Adapters/DoctrineAdapter.php
@@ -9,6 +9,8 @@ class DoctrineAdapter implements DoctrineCacheInterface
9 9 {
10 10 protected $cacheService;
11 11
  12 + protected $namespace = '';
  13 +
12 14 protected $caches = array();
13 15
14 16 public function __construct($cacheService)
@@ -16,11 +18,23 @@ public function __construct($cacheService)
16 18 $this->cacheService = $cacheService;
17 19 }
18 20
  21 + public function setNamespace($namespace)
  22 + {
  23 + $this->namespace = $namespace;
  24 + }
  25 +
  26 + public function getNamespace()
  27 + {
  28 + return $this->namespace;
  29 + }
  30 +
19 31 /**
20 32 * {@inheritDoc}
21 33 */
22 34 public function fetch($id)
23 35 {
  36 + $id = $this->normalizeId($id);
  37 +
24 38 if(isset($this->caches[$id])) {
25 39 $cache = $this->caches[$id];
26 40 unset($this->caches[$id]);
@@ -28,10 +42,12 @@ public function fetch($id)
28 42 $cache = $this->cacheService->get($id);
29 43 }
30 44
  45 +
  46 + $value = $cache->get();
31 47 if($cache->isMiss()) {
32 48 return false;
33 49 } else {
34   - return $cache->get();
  50 + return $value;
35 51 }
36 52 }
37 53
@@ -40,6 +56,8 @@ public function fetch($id)
40 56 */
41 57 public function contains($id)
42 58 {
  59 + $id = $this->normalizeId($id);
  60 +
43 61 $this->caches[$id] = $this->cacheService->get($id);
44 62
45 63 return $this->caches[$id]->isMiss();
@@ -50,6 +68,8 @@ public function contains($id)
50 68 */
51 69 public function save($id, $data, $lifeTime = 0)
52 70 {
  71 + $id = $this->normalizeId($id);
  72 +
53 73 $cache = $this->cacheService->get($id);
54 74
55 75 return $cache->set($data, $lifeTime);
@@ -60,8 +80,14 @@ public function save($id, $data, $lifeTime = 0)
60 80 */
61 81 public function delete($id)
62 82 {
63   - $cache = $this->cacheService->get($id);
64   - return $cache->clear();
  83 + $id = $this->normalizeId($id);
  84 +
  85 + return $this->cacheService->clear($id);
  86 + }
  87 +
  88 + public function deleteAll()
  89 + {
  90 + return $this->flushAll();
65 91 }
66 92
67 93 /**
@@ -77,6 +103,19 @@ public function getStats()
77 103 return $stats;
78 104 }
79 105
  106 + public function flushAll()
  107 + {
  108 + $this->delete('');
  109 + }
80 110
81   -
  111 + protected function normalizeId($id)
  112 + {
  113 + if(isset($this->namespace)) {
  114 + $id = sprintf('zz_%s_zz/%s', $this->namespace, $id);
  115 + $id = trim($id, '/');
  116 + return $id;
  117 + } else {
  118 + return $id;
  119 + }
  120 + }
82 121 }
8 Service/CacheService.php
@@ -46,13 +46,13 @@ public function get()
46 46 $args = $args[0];
47 47
48 48 array_unshift($args, $this->key);
  49 + $key = join('/', $args);
49 50
50 51 $handler = (isset($this->handler)) ? $this->handler : null;
51 52 $cache = new StashCache($handler);
52 53 $stash = new CacheResultObject($cache, $this->logger);
53 54
54   - if(count($args) > 0)
55   - $stash->setupKey($args);
  55 + $stash->setupKey($key);
56 56
57 57 return $stash;
58 58 }
@@ -65,7 +65,7 @@ public function get()
65 65 */
66 66 public function clear()
67 67 {
68   - $stash = $this->getCache(func_get_args());
  68 + $stash = $this->get(func_get_args());
69 69 return $stash->clear();
70 70 }
71 71
@@ -77,7 +77,7 @@ public function clear()
77 77 */
78 78 public function purge()
79 79 {
80   - $stash = $this->getCache();
  80 + $stash = $this->get();
81 81 return $stash->purge();
82 82 }
83 83

0 comments on commit 2986901

Please sign in to comment.
Something went wrong with that request. Please try again.