Skip to content

Commit 2cc6f49

Browse files
committed
Fixed bug on tags that are not working on the first cache write
1 parent c039f50 commit 2cc6f49

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/phpFastCache/Cache/DriverBaseTrait.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,19 @@ public function getDriverName()
214214
/**
215215
* @param \phpFastCache\Cache\ExtendedCacheItemInterface $item
216216
* @return bool
217+
* @throws \LogicException
217218
*/
218219
public function driverWriteTags(ExtendedCacheItemInterface $item)
219220
{
221+
/**
222+
* Do not attempt to write tags
223+
* on tags item, it can leads
224+
* to an infinite recursive calls
225+
*/
226+
if(strpos($item->getKey(), self::DRIVER_TAGS_KEY_PREFIX ) === 0){
227+
throw new \LogicException('Trying to set tag(s) to an Tag item index: ' . $item->getKey());
228+
}
229+
220230
$tagsItems = $this->getItems($this->getTagKeys($item->getTags()));
221231

222232
foreach ($tagsItems as $tagsItem) {
@@ -241,6 +251,7 @@ public function driverWriteTags(ExtendedCacheItemInterface $item)
241251
$tagsItem->expiresAt($item->getExpirationDate());
242252
}
243253
$this->driverWrite($tagsItem);
254+
$tagsItem->setHit(true);
244255
}
245256

246257
/**
@@ -265,6 +276,7 @@ public function driverWriteTags(ExtendedCacheItemInterface $item)
265276
if (count($data)) {
266277
$tagsItem->expiresAt(max($data));
267278
$this->driverWrite($tagsItem);
279+
$tagsItem->setHit(true);
268280
} else {
269281
$this->driverDelete($tagsItem);
270282
}

0 commit comments

Comments
 (0)