asm89 / twig-cache-extension

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

Allow override lifetime per block when using GenerationalCacheStrategy #35

Open Koc opened 8 years ago

Koc commented 8 years ago

There is no way set ttl for the block, only per cache strategy

rvanlaak commented 8 years ago

Yes that is correct, or you can combine them using IndexedChainingCacheStrategy.

{% cache 'v1/summary' {time: 300} %}

So what actually is the bug / issue?

Koc commented 8 years ago

I am using IndexedChainingCacheStrategy+GenerationalCacheStrategy+Blackhole. The problem is ttl for GenerationalCacheStrategy is preconfigured inside constructor. So I cann't do something

{% cache 'v1/summary' {generational: {'id': article.id, '@ttl' => 100}} %}

I can create PR for ttl per block and tagging (#36). But what syntax do you prefer:

{% cache 'v1/summary' {generational: {'id': article.id, '@ttl' => 100. '@tags' => ['user-'~article.author.id]}} %}
{# or #}
{% cache 'v1/summary' {generational: {'id': article.id, '_ttl' => 100. '_tags' => ['user-'~article.author.id]}} %}
{# or #}
{% cache 'v1/summary' {generational: {'id': article.id} ttl 100 tags ['user-'~article.author.id] %}

or we can be inspired from https://craftcms.com/docs/templating/cache

rvanlaak commented 8 years ago

The key is time instead of ttl or the other ones you mention. :+1:

An example of chaining: https://github.com/asm89/twig-cache-extension#setup-2

So if I'm correct this isn't a bug in the extension right?

Koc commented 8 years ago

This is a feature request, not bug

rvanlaak commented 8 years ago

You can already set the ttl for a block by using (or chaining) the LifetimeCacheStrategy.

Koc commented 8 years ago

I don't want use LifetimeCacheStrategy :). I need support per-block ttl for GenerationalCacheStrategy (as noticed in subject of this issue). Nevermind, I will create PR for this later.