asm89 / twig-cache-extension

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

Add toggle to Twig tag to toggle cache #20

Closed ruudk closed 10 years ago

ruudk commented 10 years ago

I have a website that has a lot of festivals and concerts (events). I want to cache the whole output of the page to speed things up. But when a festival is in the past (expired) I don't want to serve it from cache but just fresh from the database. Those pages aren't visited very often so there is no need to cache it.

Would it be possible to add an extra flag to the {% cache %} block to allow the toggle?

For example:

{% cache 'events' { key: 'event_' ~ event.id } event.shouldCache %}
  output
{% endcache %}
ruudk commented 10 years ago

Or is the best way to do this by implementing it inside my Strategy?

asm89 commented 10 years ago

@ruudk I'd say implementing it in your strategy would be the best option. Did you end up doing it like that?

ruudk commented 10 years ago

Yep! :)