Skip to content

Commit 9e7e777

Browse files
authored
Merge pull request #114 from Nyholm/expiration-timestamp
Expiration timestamp
2 parents b05c31e + eb3aec0 commit 9e7e777

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

FilesystemCachePool.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Cache\Adapter\Common\AbstractCachePool;
1515
use Cache\Adapter\Common\Exception\InvalidArgumentException;
16+
use Cache\Adapter\Common\PhpCacheItem;
1617
use Cache\Taggable\TaggableItemInterface;
1718
use Cache\Taggable\TaggablePoolInterface;
1819
use 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

Comments
 (0)