Skip to content
Advertisement

cache with dynamic pages

I am currently developing a WEB site on symfony 6 and during production testing I have a problem with the TWIG cache. Indeed, my site includes a page editing feature. So when rendering the first time, the page is rendered correctly. However, if the editor then modifies the page, and I return to the page is still the old version. Is there a way to integrate a cache check, for example it looks at the hash of the loaded template has not changed?

How is the page loaded:

{% extends 'base.html.twig' %}

{% block title %}
    {{project.libelle}}
{% endblock %}
{% block content %}
    <div class="content">
        {{ckRender(include("dynamique/" ~ project.page.filename))}}
    </div>
{% endblock %}

Thank you for your help

Advertisement

Answer

Thank you DarkBee.

I had seen the forum but not necessarily read in detail. With a bit of research here is what we can do (for those who are interested):

There are two possibilities:

  • the best : modify the configuration file “/config/packages/twig.yand” and add “auto_reload: true”.
  • the other, add instead “cache: false”

With the first method, twig checks otherwise the files have been modified (light cost for performance), in the second twig always regenerates the template, so no cache (high cost for performance).

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement