1212namespace Cache \Adapter \Predis ;
1313
1414use Cache \Adapter \Common \AbstractCachePool ;
15+ use Cache \Hierarchy \HierarchicalCachePoolTrait ;
16+ use Cache \Hierarchy \HierarchicalPoolInterface ;
1517use Predis \Client ;
1618use Psr \Cache \CacheItemInterface ;
1719
1820/**
19- * @author Aaron Scherer <aequasi@gmail.com>
2021 * @author Tobias Nyholm <tobias.nyholm@gmail.com>
2122 */
22- class PredisCachePool extends AbstractCachePool
23+ class PredisCachePool extends AbstractCachePool implements HierarchicalPoolInterface
2324{
25+ use HierarchicalCachePoolTrait;
26+
2427 /**
2528 * @type Client
2629 */
@@ -34,24 +37,9 @@ public function __construct(Client $cache)
3437 $ this ->cache = $ cache ;
3538 }
3639
37- /**
38- * {@inheritdoc}
39- */
40- public function hasItem ($ key , array $ tags = [])
41- {
42- $ this ->validateKey ($ key );
43- $ taggedKey = $ this ->generateCacheKey ($ key , $ tags );
44-
45- if (isset ($ this ->deferred [$ key ])) {
46- return true ;
47- }
48-
49- return $ this ->cache ->exists ($ taggedKey );
50- }
51-
5240 protected function fetchObjectFromCache ($ key )
5341 {
54- return unserialize ($ this ->cache ->get ($ key ));
42+ return unserialize ($ this ->cache ->get ($ this -> getHierarchyKey ( $ key) ));
5543 }
5644
5745 protected function clearAllObjectsFromCache ()
@@ -61,15 +49,28 @@ protected function clearAllObjectsFromCache()
6149
6250 protected function clearOneObjectFromCache ($ key )
6351 {
64- return $ this ->cache ->del ($ key ) >= 0 ;
52+ // We have to commit here to be able to remove deferred hierarchy items
53+ $ this ->commit ();
54+
55+ $ keyString = $ this ->getHierarchyKey ($ key , $ path );
56+ $ this ->cache ->incr ($ path );
57+ $ this ->clearHierarchyKeyCache ();
58+
59+ return $ this ->cache ->del ($ keyString ) >= 0 ;
6560 }
6661
6762 protected function storeItemInCache ($ key , CacheItemInterface $ item , $ ttl )
6863 {
64+ $ key = $ this ->getHierarchyKey ($ key );
6965 if ($ ttl === null ) {
7066 return 'OK ' === $ this ->cache ->set ($ key , serialize ($ item ))->getPayload ();
7167 }
7268
7369 return 'OK ' === $ this ->cache ->setex ($ key , $ ttl , serialize ($ item ))->getPayload ();
7470 }
71+
72+ protected function getValueFormStore ($ key )
73+ {
74+ return $ this ->cache ->get ($ key );
75+ }
7576}
0 commit comments