1313
1414use Cache \Adapter \Common \AbstractCachePool ;
1515use Cache \Adapter \Common \Exception \InvalidArgumentException ;
16+ use Cache \Adapter \Common \PhpCacheItem ;
1617use Cache \Taggable \TaggableItemInterface ;
1718use Cache \Taggable \TaggablePoolInterface ;
1819use Cache \Taggable \TaggablePoolTrait ;
@@ -65,7 +66,7 @@ public function setFolder($folder)
6566 */
6667 protected function fetchObjectFromCache ($ key )
6768 {
68- $ empty = [false , null , []];
69+ $ empty = [false , null , [], null ];
6970 $ file = $ this ->getFilePath ($ key );
7071
7172 try {
@@ -77,16 +78,18 @@ protected function fetchObjectFromCache($key)
7778 return $ empty ;
7879 }
7980
80- if ($ data [0 ] !== null && time () > $ data [0 ]) {
81- foreach ($ data [2 ] as $ tag ) {
81+ // Determine expirationTimestamp from data, remove items if expired
82+ $ expirationTimestamp = $ data [2 ] ?: null ;
83+ if ($ expirationTimestamp !== null && time () > $ expirationTimestamp ) {
84+ foreach ($ data [1 ] as $ tag ) {
8285 $ this ->removeListItem ($ this ->getTagKey ($ tag ), $ key );
8386 }
8487 $ this ->forceClear ($ key );
8588
8689 return $ empty ;
8790 }
8891
89- return [true , $ data [1 ], $ data [2 ] ];
92+ return [true , $ data [0 ], $ data [1 ], $ expirationTimestamp ];
9093 }
9194
9295 /**
@@ -113,7 +116,7 @@ protected function clearOneObjectFromCache($key)
113116 /**
114117 * {@inheritdoc}
115118 */
116- protected function storeItemInCache (CacheItemInterface $ item , $ ttl )
119+ protected function storeItemInCache (PhpCacheItem $ item , $ ttl )
117120 {
118121 $ tags = [];
119122 if ($ item instanceof TaggableItemInterface) {
@@ -122,9 +125,9 @@ protected function storeItemInCache(CacheItemInterface $item, $ttl)
122125
123126 $ data = serialize (
124127 [
125- ($ ttl === null ? null : time () + $ ttl ),
126128 $ item ->get (),
127129 $ tags ,
130+ $ item ->getExpirationTimestamp (),
128131 ]
129132 );
130133
0 commit comments