Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

Using Cache Tags

use SymfonyContractsCacheItemInterface;
use SymfonyContractsCacheTagAwareCacheInterface;

class SomeClass
{
    private $myCachePool;

    // using autowiring to inject the cache pool
    public function __construct(TagAwareCacheInterface $myCachePool)
    {
        $this->myCachePool = $myCachePool;
    }

    public function someMethod()
    {
        $value0 = $this->myCachePool->get('item_0', function (ItemInterface $item) {
            $item->tag(['foo', 'bar']);

            return 'debug';
        });

        $value1 = $this->myCachePool->get('item_1', function (ItemInterface $item) {
            $item->tag('foo');

            return 'debug';
        });

        // Remove all cache keys tagged with "bar"
        $this->myCachePool->invalidateTags(['bar']);
    }
}
Source by symfony.com #
 
PREVIOUS NEXT
Tagged: #Using #Cache #Tags
ADD COMMENT
Topic
Name
8+8 =