asm89 / twig-cache-extension

The missing cache extension for Twig. Caching template fragments with Twig.
MIT License
388 stars 27 forks source link

How this suppose to work? #39

Closed piernik closed 7 years ago

piernik commented 7 years ago

In php I'm defining time=time(); This is my twig code:

{% cache 'v1' 10000 %}
    Hello! {{ time }}
{% endcache %}

Every time I hit refresh I have new timestamp. Doesn't it suppose to be fixed for 10 seconds?

rvanlaak commented 7 years ago

Well, that depends on your configuration, what cache strategy do you use? Where do you define time? Please elaborate a bit.

piernik commented 7 years ago

I though that 10000 is time in miliseconds - is it not?

rvanlaak commented 7 years ago

That depends on your configuration, what caching strategy did you configure?

https://github.com/asm89/twig-cache-extension#setup

piernik commented 7 years ago

The first one:

$cacheProvider = new DoctrineCacheAdapter(new ArrayCache());
$cacheStrategy = new LifetimeCacheStrategy($cacheProvider);
$cacheExtension = new Extension($cacheStrategy);
asm89 commented 7 years ago

@piernik The array cache will not persist across requests. It just caches in an array. That's mainly useful for demo purposes or perhaps if you are re-using the same blocks in one request. If you use doctrine cache make sure to set up a different cache, e.g. apc or memcache.