Template Smarty. There is a template that is the same for a specific section of pages, except for the dynamic part, the data of which is obtained from the database. If it is included in the cache, the data from the database will not change when moving to the next material of the same section (template). If we exclude the dynamic part with the help of {nocache} tags, then queries to the database to get the dynamic part will be executed at each input on the same material.

Question: how to enable caching of the static part of the template, and the dynamic call to perform only once, and then cache it.

ps The use of cache_id not suitable (since it caches static elements of the template each time, the cache’s meaning is lost for pages that are visited 1 time)

  • Hmmm, it's strange that I missed from the documentation that cache_id can be assigned to include . Now I’ll throw the dynamic part into separate templates and include them in the static ones with include c cache id . Should work. - Zhenya40

1 answer 1

My decision:

We leave in the original template only the static part. Dynamic placed in a separate template. We do include with the assigned cache_id .

Result: The static part is loaded only once. The dynamic part is also only once. All subsequent times the initial static pattern is taken and the dynamic part by id, if not, then it is created.

In the backend, set the is_cached check before executing the query to the database.