[Cache] ignore unserialization failures in AbstractTagAwareAdapter::doDelete()

This commit is contained in:
Nicolas Grekas 2019-10-09 19:31:25 +02:00
parent 1292d8da7c
commit a1f334c1b7
2 changed files with 14 additions and 6 deletions

View File

@ -229,10 +229,14 @@ abstract class AbstractTagAwareAdapter implements TagAwareAdapterInterface, TagA
unset($this->deferred[$key]);
}
foreach ($this->doFetch($ids) as $id => $value) {
foreach ($value['tags'] ?? [] as $tag) {
$tagData[$this->getId(self::TAGS_PREFIX.$tag)][] = $id;
try {
foreach ($this->doFetch($ids) as $id => $value) {
foreach ($value['tags'] ?? [] as $tag) {
$tagData[$this->getId(self::TAGS_PREFIX.$tag)][] = $id;
}
}
} catch (\Exception $e) {
// ignore unserialization failures
}
try {

View File

@ -97,7 +97,7 @@ class RedisTagAwareAdapter extends AbstractTagAwareAdapter
}
// While pipeline isn't supported on RedisCluster, other setups will at least benefit from doing this in one op
$results = $this->pipeline(static function () use ($serialized, $lifetime, $addTagData, $delTagData) {
$results = $this->pipeline(static function () use ($serialized, $lifetime, $addTagData, $delTagData, $failed) {
// Store cache items, force a ttl if none is set, as there is no MSETEX we need to set each one
foreach ($serialized as $id => $value) {
yield 'setEx' => [
@ -109,11 +109,15 @@ class RedisTagAwareAdapter extends AbstractTagAwareAdapter
// Add and Remove Tags
foreach ($addTagData as $tagId => $ids) {
yield 'sAdd' => array_merge([$tagId], $ids);
if (!$failed || $ids = array_diff($ids, $failed)) {
yield 'sAdd' => array_merge([$tagId], $ids);
}
}
foreach ($delTagData as $tagId => $ids) {
yield 'sRem' => array_merge([$tagId], $ids);
if (!$failed || $ids = array_diff($ids, $failed)) {
yield 'sRem' => array_merge([$tagId], $ids);
}
}
});