Skip to content

Commit b550d73

Browse files
authored
Merge pull request #318 from Geolim4/final
Fixed bug on tags that are not working on the first cache write
2 parents 9d1b718 + 7e77617 commit b550d73

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/phpFastCache/Cache/DriverBaseTrait.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,22 @@ 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+
230+
/**
231+
* @var $tagsItems ExtendedCacheItemInterface[]
232+
*/
220233
$tagsItems = $this->getItems($this->getTagKeys($item->getTags()));
221234

222235
foreach ($tagsItems as $tagsItem) {
@@ -241,6 +254,7 @@ public function driverWriteTags(ExtendedCacheItemInterface $item)
241254
$tagsItem->expiresAt($item->getExpirationDate());
242255
}
243256
$this->driverWrite($tagsItem);
257+
$tagsItem->setHit(true);
244258
}
245259

246260
/**
@@ -265,6 +279,7 @@ public function driverWriteTags(ExtendedCacheItemInterface $item)
265279
if (count($data)) {
266280
$tagsItem->expiresAt(max($data));
267281
$this->driverWrite($tagsItem);
282+
$tagsItem->setHit(true);
268283
} else {
269284
$this->driverDelete($tagsItem);
270285
}

0 commit comments

Comments
 (0)