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 <[email protected] > 2021 * @author Tobias Nyholm <[email protected] > 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,25 @@ protected function clearAllObjectsFromCache()
6149
6250 protected function clearOneObjectFromCache ($ key )
6351 {
64- return $ this ->cache ->del ($ key ) >= 0 ;
52+ $ keyString = $ this ->getHierarchyKey ($ key , $ path );
53+ $ this ->cache ->incr ($ path );
54+ $ this ->clearHierarchyKeyCache ();
55+
56+ return $ this ->cache ->del ($ keyString ) >= 0 ;
6557 }
6658
6759 protected function storeItemInCache ($ key , CacheItemInterface $ item , $ ttl )
6860 {
61+ $ key = $ this ->getHierarchyKey ($ key );
6962 if ($ ttl === null ) {
7063 return 'OK ' === $ this ->cache ->set ($ key , serialize ($ item ))->getPayload ();
7164 }
7265
7366 return 'OK ' === $ this ->cache ->setex ($ key , $ ttl , serialize ($ item ))->getPayload ();
7467 }
68+
69+ protected function getValueFormStore ($ key )
70+ {
71+ return $ this ->cache ->get ($ key );
72+ }
7573}
0 commit comments