@@ -41,10 +41,15 @@ protected function fetchObjectFromCache($key)
4141 {
4242 $ file = $ this ->getFilePath ($ key );
4343 if (!$ this ->filesystem ->has ($ file )) {
44- return ;
44+ return [ false , null ] ;
4545 }
4646
47- return unserialize ($ this ->filesystem ->read ($ file ));
47+ $ data = unserialize ($ this ->filesystem ->read ($ file ));
48+ if (time () > $ data [0 ]) {
49+ return [false , null ];
50+ }
51+
52+ return [true , $ data [1 ]];
4853 }
4954
5055 protected function clearAllObjectsFromCache ()
@@ -71,19 +76,20 @@ protected function storeItemInCache($key, CacheItemInterface $item, $ttl)
7176 $ this ->filesystem ->delete ($ file );
7277 }
7378
74- return $ this ->filesystem ->write ($ file , serialize ($ item ));
79+ return $ this ->filesystem ->write ($ file , serialize ([ time () + $ ttl , $ item-> get ()] ));
7580 }
7681
7782 /**
7883 * @param string $key
7984 *
80- * @return string
8185 * @throws InvalidArgumentException
86+ *
87+ * @return string
8288 */
8389 private function getFilePath ($ key )
8490 {
85- if (!preg_match ('|^[a-zA-Z0-9_\.: ]+$| ' , $ key )) {
86- throw new InvalidArgumentException (sprintf ('Invalid key "%s". Valid keys must match [a-zA-Z0-9_\.: ]. ' , $ key ));
91+ if (!preg_match ('|^[a-zA-Z0-9_\.! ]+$| ' , $ key )) {
92+ throw new InvalidArgumentException (sprintf ('Invalid key "%s". Valid keys must match [a-zA-Z0-9_\.! ]. ' , $ key ));
8793 }
8894
8995 return sprintf ('%s/%s ' , self ::CACHE_PATH , $ key );
0 commit comments