@@ -163,14 +163,12 @@ public function warmUp(array $values)
163
163
*/
164
164
public function getItem ($ key )
165
165
{
166
- if (null === $ this ->values ) {
167
- $ this ->initialize ();
168
- }
169
-
170
166
if (!is_string ($ key )) {
171
167
throw new InvalidArgumentException (sprintf ('Cache key must be string, "%s" given. ' , is_object ($ key ) ? get_class ($ key ) : gettype ($ key )));
172
168
}
173
-
169
+ if (null === $ this ->values ) {
170
+ $ this ->initialize ();
171
+ }
174
172
if (!isset ($ this ->values [$ key ])) {
175
173
return $ this ->fallbackPool ->getItem ($ key );
176
174
}
@@ -203,15 +201,14 @@ public function getItem($key)
203
201
*/
204
202
public function getItems (array $ keys = array ())
205
203
{
206
- if (null === $ this ->values ) {
207
- $ this ->initialize ();
208
- }
209
-
210
204
foreach ($ keys as $ key ) {
211
205
if (!is_string ($ key )) {
212
206
throw new InvalidArgumentException (sprintf ('Cache key must be string, "%s" given. ' , is_object ($ key ) ? get_class ($ key ) : gettype ($ key )));
213
207
}
214
208
}
209
+ if (null === $ this ->values ) {
210
+ $ this ->initialize ();
211
+ }
215
212
216
213
return $ this ->generateItems ($ keys );
217
214
}
@@ -221,13 +218,12 @@ public function getItems(array $keys = array())
221
218
*/
222
219
public function hasItem ($ key )
223
220
{
224
- if (null === $ this ->values ) {
225
- $ this ->initialize ();
226
- }
227
-
228
221
if (!is_string ($ key )) {
229
222
throw new InvalidArgumentException (sprintf ('Cache key must be string, "%s" given. ' , is_object ($ key ) ? get_class ($ key ) : gettype ($ key )));
230
223
}
224
+ if (null === $ this ->values ) {
225
+ $ this ->initialize ();
226
+ }
231
227
232
228
return isset ($ this ->values [$ key ]) || $ this ->fallbackPool ->hasItem ($ key );
233
229
}
@@ -249,13 +245,12 @@ public function clear()
249
245
*/
250
246
public function deleteItem ($ key )
251
247
{
252
- if (null === $ this ->values ) {
253
- $ this ->initialize ();
254
- }
255
-
256
248
if (!is_string ($ key )) {
257
249
throw new InvalidArgumentException (sprintf ('Cache key must be string, "%s" given. ' , is_object ($ key ) ? get_class ($ key ) : gettype ($ key )));
258
250
}
251
+ if (null === $ this ->values ) {
252
+ $ this ->initialize ();
253
+ }
259
254
260
255
return !isset ($ this ->values [$ key ]) && $ this ->fallbackPool ->deleteItem ($ key );
261
256
}
@@ -265,10 +260,6 @@ public function deleteItem($key)
265
260
*/
266
261
public function deleteItems (array $ keys )
267
262
{
268
- if (null === $ this ->values ) {
269
- $ this ->initialize ();
270
- }
271
-
272
263
$ deleted = true ;
273
264
$ fallbackKeys = array ();
274
265
@@ -283,6 +274,9 @@ public function deleteItems(array $keys)
283
274
$ fallbackKeys [] = $ key ;
284
275
}
285
276
}
277
+ if (null === $ this ->values ) {
278
+ $ this ->initialize ();
279
+ }
286
280
287
281
if ($ fallbackKeys ) {
288
282
$ deleted = $ this ->fallbackPool ->deleteItems ($ fallbackKeys ) && $ deleted ;
@@ -328,7 +322,7 @@ public function commit()
328
322
*/
329
323
private function initialize ()
330
324
{
331
- $ this ->values = @( include $ this ->file ) ? : array ();
325
+ $ this ->values = file_exists ( $ this -> file ) ? ( include $ this ->file ?: array ()) : array ();
332
326
}
333
327
334
328
/**
0 commit comments