Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

AmaraLiving/twig-cache-extension-symfony

Repository files navigation

Twig cache extension / Symfony cache bridge

Build Status Coverage Status

Tiny library to allow use of tagging cache items from the Symfony2 cache component with the twig cache extension.

It has a SymfonyTaggedCacheStrategy which accepts tags.

<?php

use Asm89\Twig\CacheExtension\Extension as CacheExtension;
use Amara\TwigCacheExtension\SymfonyTaggedCacheStrategy;
use Symfony\Component\Cache\Adapter\NullAdapter;
use Symfony\Component\Cache\Adapter\TagAwareAdapter;

$adapter = new TagAwareAdapter(new NullAdapter());

$cacheStrategy = new SymfonyTaggedCacheStrategy($adapter);

$cacheExtension = new CacheExtension($cacheStrategy);

$twig->addExtension($cacheExtension);

We can now use the twig view cache with tagged values:

{% cache 'example-item' {lifetime: 900, tags: ['tag1', 'tag2']} %}
    The content to cache
{% endcache %}

Why a separate library?

The Twig cache extension supports a PSR cache, but it does not support tagging. This library exists to avoid introducing a Symfony dependency into the Twig cache extension.

About

Twig cache extension / Symfony cache bridge

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages