How do you work with cache?
Created 6 years ago by william

Not sure if there is a bug or something in 3.4, but i have a hard time working with cache now.

For example, i have my own module events

This caches , but when i add or change an event. It does not auto invalidate:

{% set events = nextEvents('events').latest().paginate(9) %}
{% cache events 50 %}
    {% include 'project.module.events::partials/next-events' with {'events':events } %}
{% endcache %}

Do i need to hook into an event and clear cache to get it to work? Or should this be taken care of behind the scenes?

fryiee  —  6 years ago

@william, is this inside of a cached view? It will not invalidate the parent cached view. Bit of an issue if using grids.

william  —  6 years ago

With a cached view, do you mean the view or a partial view? The full code is basically:

{% set events = nextEvents('events').latest().paginate(9) %}
{% cache events 50 %}
    {% include 'project.module.events::partials/next-events' with {'events':events } %}
{% endcache %}
ryanthompson  —  6 years ago

Make sure that your model is bound JIC. But this looks perfectly fine. Models invalidate their own cache when they are updated in any way.