@@ -35,7 +35,9 @@ class ChainAdapter implements AdapterInterface, CacheInterface, PruneableInterfa
35
35
36
36
private $ adapters = [];
37
37
private $ adapterCount ;
38
- private $ syncItem ;
38
+ private $ defaultLifetime ;
39
+
40
+ private static $ syncItem ;
39
41
40
42
/**
41
43
* @param CacheItemPoolInterface[] $adapters The ordered list of adapters used to fetch cached items
@@ -62,9 +64,10 @@ public function __construct(array $adapters, int $defaultLifetime = 0)
62
64
}
63
65
}
64
66
$ this ->adapterCount = \count ($ this ->adapters );
67
+ $ this ->defaultLifetime = $ defaultLifetime ;
65
68
66
- $ this -> syncItem = \Closure::bind (
67
- static function ($ sourceItem , $ item , $ sourceMetadata = null ) use ( $ defaultLifetime ) {
69
+ self :: $ syncItem ?? self :: $ syncItem = \Closure::bind (
70
+ static function ($ sourceItem , $ item , $ defaultLifetime , $ sourceMetadata = null ) {
68
71
$ sourceItem ->isTaggable = false ;
69
72
$ sourceMetadata = $ sourceMetadata ?? $ sourceItem ->metadata ;
70
73
unset($ sourceMetadata [CacheItem::METADATA_TAGS ]);
@@ -105,7 +108,7 @@ public function get(string $key, callable $callback, float $beta = null, array &
105
108
$ value = $ this ->doGet ($ adapter , $ key , $ callback , $ beta , $ metadata );
106
109
}
107
110
if (null !== $ item ) {
108
- ($ this -> syncItem )($ lastItem = $ lastItem ?? $ item , $ item , $ metadata );
111
+ (self :: $ syncItem )($ lastItem = $ lastItem ?? $ item , $ item, $ this -> defaultLifetime , $ metadata );
109
112
}
110
113
111
114
return $ value ;
@@ -119,15 +122,15 @@ public function get(string $key, callable $callback, float $beta = null, array &
119
122
*/
120
123
public function getItem ($ key )
121
124
{
122
- $ syncItem = $ this -> syncItem ;
125
+ $ syncItem = self :: $ syncItem ;
123
126
$ misses = [];
124
127
125
128
foreach ($ this ->adapters as $ i => $ adapter ) {
126
129
$ item = $ adapter ->getItem ($ key );
127
130
128
131
if ($ item ->isHit ()) {
129
132
while (0 <= --$ i ) {
130
- $ this ->adapters [$ i ]->save ($ syncItem ($ item , $ misses [$ i ]));
133
+ $ this ->adapters [$ i ]->save ($ syncItem ($ item , $ misses [$ i ], $ this -> defaultLifetime ));
131
134
}
132
135
133
136
return $ item ;
@@ -164,13 +167,13 @@ private function generateItems(iterable $items, int $adapterIndex)
164
167
}
165
168
166
169
if ($ missing ) {
167
- $ syncItem = $ this -> syncItem ;
170
+ $ syncItem = self :: $ syncItem ;
168
171
$ adapter = $ this ->adapters [$ adapterIndex ];
169
172
$ items = $ this ->generateItems ($ nextAdapter ->getItems ($ missing ), $ nextAdapterIndex );
170
173
171
174
foreach ($ items as $ k => $ item ) {
172
175
if ($ item ->isHit ()) {
173
- $ adapter ->save ($ syncItem ($ item , $ misses [$ k ]));
176
+ $ adapter ->save ($ syncItem ($ item , $ misses [$ k ], $ this -> defaultLifetime ));
174
177
}
175
178
176
179
yield $ k => $ item ;
0 commit comments