public function remove($entryIdentifier)
{
if ($this->isFrozen()) {
throw new \RuntimeException(sprintf('Cannot remove cache entry because the backend of cache "%s" is frozen.', $this->cacheIdentifier), 1323344192);
}
do {
$tagsKey = $this->buildKey('tags:' . $entryIdentifier);
$this->redis->watch($tagsKey);
$tags = $this->redis->sMembers($tagsKey);
$this->redis->multi();
$this->redis->del($this->buildKey('entry:' . $entryIdentifier));
foreach ($tags as $tag) {
$this->redis->sRem($this->buildKey('tag:' . $tag), $entryIdentifier);
}
$this->redis->del($this->buildKey('tags:' . $entryIdentifier));
$this->redis->lRem($this->buildKey('entries'), $entryIdentifier, 0);
$result = $this->redis->exec();
} while ($result === false);
return true;
}
/** * @test */ public function removeRemovesEntryFromCache() { for ($i = 0; $i < 10; $i++) { $this->backend->set('entry_' . $i, 'foo', ['tag1']); } $this->assertCount(10, $this->backend->findIdentifiersByTag('tag1')); $this->assertEquals('foo', $this->backend->get('entry_1')); $actualEntries = []; foreach ($this->backend as $key => $value) { $actualEntries[] = $key; } $this->assertCount(10, $actualEntries); $this->backend->remove('entry_3'); $this->assertCount(9, $this->backend->findIdentifiersByTag('tag1')); $this->assertFalse($this->backend->get('entry_3')); $actualEntries = []; foreach ($this->backend as $key => $value) { $actualEntries[] = $key; } $this->assertCount(9, $actualEntries); }