1313
1414use Psr \Cache \CacheItemInterface ;
1515use Psr \Cache \CacheItemPoolInterface ;
16+ use Symfony \Component \Cache \CacheInterface ;
1617use Symfony \Component \Cache \CacheItem ;
1718use Symfony \Component \Cache \Exception \InvalidArgumentException ;
1819use Symfony \Component \Cache \PruneableInterface ;
1920use Symfony \Component \Cache \ResettableInterface ;
21+ use Symfony \Component \Cache \Traits \GetTrait ;
2022
2123/**
2224 * Chains several adapters together.
2628 *
2729 * @author Kévin Dunglas <dunglas@gmail.com>
2830 */
29- class ChainAdapter implements AdapterInterface, PruneableInterface, ResettableInterface
31+ class ChainAdapter implements AdapterInterface, CacheInterface, PruneableInterface, ResettableInterface
3032{
33+ use GetTrait;
34+
3135 private $ adapters = array ();
3236 private $ adapterCount ;
3337 private $ syncItem ;
@@ -60,6 +64,10 @@ function ($sourceItem, $item) use ($defaultLifetime) {
6064 $ item ->value = $ sourceItem ->value ;
6165 $ item ->expiry = $ sourceItem ->expiry ;
6266 $ item ->isHit = $ sourceItem ->isHit ;
67+ $ item ->stats = $ sourceItem ->stats ;
68+
69+ $ sourceItem ->isTaggable = false ;
70+ unset($ sourceItem ->stats [CacheItem::STATS_TAGS ]);
6371
6472 if (0 < $ sourceItem ->defaultLifetime && $ sourceItem ->defaultLifetime < $ defaultLifetime ) {
6573 $ defaultLifetime = $ sourceItem ->defaultLifetime ;
@@ -75,6 +83,33 @@ function ($sourceItem, $item) use ($defaultLifetime) {
7583 );
7684 }
7785
86+ /**
87+ * {@inheritdoc}
88+ */
89+ public function get (string $ key , callable $ callback )
90+ {
91+ $ lastItem = null ;
92+ $ i = 0 ;
93+ $ wrap = function (CacheItem $ item = null ) use ($ key , $ callback , &$ wrap , &$ i , &$ lastItem ) {
94+ $ adapter = $ this ->adapters [$ i ];
95+ if (isset ($ this ->adapters [++$ i ])) {
96+ $ callback = $ wrap ;
97+ }
98+ if ($ adapter instanceof CacheInterface) {
99+ $ value = $ adapter ->get ($ key , $ callback );
100+ } else {
101+ $ value = $ this ->doGet ($ adapter , $ key , $ callback );
102+ }
103+ if (null !== $ item ) {
104+ ($ this ->syncItem )($ lastItem = $ lastItem ?? $ item , $ item );
105+ }
106+
107+ return $ value ;
108+ };
109+
110+ return $ wrap ();
111+ }
112+
78113 /**
79114 * {@inheritdoc}
80115 */
0 commit comments