File tree 2 files changed +18
-9
lines changed
src/Symfony/Component/Cache
2 files changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -158,9 +158,10 @@ public function invalidateTags(array $tags)
158
158
*/
159
159
public function hasItem ($ key )
160
160
{
161
- if ($ this ->deferred ) {
161
+ if (\is_string ( $ key ) && isset ( $ this ->deferred [ $ key ]) ) {
162
162
$ this ->commit ();
163
163
}
164
+
164
165
if (!$ this ->pool ->hasItem ($ key )) {
165
166
return false ;
166
167
}
@@ -201,18 +202,21 @@ public function getItem($key)
201
202
*/
202
203
public function getItems (array $ keys = [])
203
204
{
204
- if ($ this ->deferred ) {
205
- $ this ->commit ();
206
- }
207
205
$ tagKeys = [];
206
+ $ commit = false ;
208
207
209
208
foreach ($ keys as $ key ) {
210
209
if ('' !== $ key && \is_string ($ key )) {
211
210
$ key = static ::TAGS_PREFIX .$ key ;
212
211
$ tagKeys [$ key ] = $ key ;
212
+ $ commit = $ commit || isset ($ this ->deferred [$ key ]);
213
213
}
214
214
}
215
215
216
+ if ($ commit ) {
217
+ $ this ->commit ();
218
+ }
219
+
216
220
try {
217
221
$ items = $ this ->pool ->getItems ($ tagKeys + $ keys );
218
222
} catch (InvalidArgumentException $ e ) {
Original file line number Diff line number Diff line change @@ -39,10 +39,11 @@ trait AbstractAdapterTrait
39
39
*/
40
40
public function getItem ($ key )
41
41
{
42
- if ($ this ->deferred ) {
42
+ $ id = $ this ->getId ($ key );
43
+
44
+ if (isset ($ this ->deferred [$ key ])) {
43
45
$ this ->commit ();
44
46
}
45
- $ id = $ this ->getId ($ key );
46
47
47
48
$ f = $ this ->createCacheItem ;
48
49
$ isHit = false ;
@@ -66,14 +67,18 @@ public function getItem($key)
66
67
*/
67
68
public function getItems (array $ keys = [])
68
69
{
69
- if ($ this ->deferred ) {
70
- $ this ->commit ();
71
- }
72
70
$ ids = [];
71
+ $ commit = false ;
73
72
74
73
foreach ($ keys as $ key ) {
75
74
$ ids [] = $ this ->getId ($ key );
75
+ $ commit = $ commit || isset ($ this ->deferred [$ key ]);
76
76
}
77
+
78
+ if ($ commit ) {
79
+ $ this ->commit ();
80
+ }
81
+
77
82
try {
78
83
$ items = $ this ->doFetch ($ ids );
79
84
} catch (\Exception $ e ) {
You can’t perform that action at this time.
0 commit comments