Neos\Cache\Backend\RedisBackend::flushByTag PHP Метод

flushByTag() публичный Метод

Removes all cache entries of this cache which are tagged by the specified tag.
public flushByTag ( string $tag ) : integer
$tag string The tag the entries must have
Результат integer The number of entries which have been affected by this flush
    public function flushByTag($tag)
    {
        if ($this->isFrozen()) {
            throw new \RuntimeException(sprintf('Cannot add or modify cache entry because the backend of cache "%s" is frozen.', $this->cacheIdentifier), 1323344192);
        }
        $script = "\n\t\tlocal entries = redis.call('SMEMBERS', KEYS[1])\n\t\tfor k1,entryIdentifier in ipairs(entries) do\n\t\t\tredis.call('DEL', ARGV[1]..'entry:'..entryIdentifier)\n\t\t\tlocal tags = redis.call('SMEMBERS', ARGV[1]..'tags:'..entryIdentifier)\n\t\t\tfor k2,tagName in ipairs(tags) do\n\t\t\t\tredis.call('SREM', ARGV[1]..'tag:'..tagName, entryIdentifier)\n\t\t\tend\n\t\t\tredis.call('DEL', ARGV[1]..'tags:'..entryIdentifier)\n\t\t\tredis.call('LREM', KEYS[2], 0, entryIdentifier)\n\t\tend\n\t\treturn #entries\n\t\t";
        $count = $this->redis->eval($script, [$this->buildKey('tag:' . $tag), $this->buildKey('entries'), $this->buildKey('')], 2);
        return $count;
    }

Usage Example

 /**
  * @test
  */
 public function flushByTagRemovesEntries()
 {
     $this->backend->set('some_entry', 'foo', ['tag1', 'tag2']);
     $this->backend->flushByTag('tag1');
     $entryIdentifiers = [];
     foreach ($this->backend as $entryIdentifier => $entryValue) {
         $entryIdentifiers[] = $entryIdentifier;
     }
     $this->assertEquals([], $entryIdentifiers);
 }