martenframework / marten

The pragmatic web framework.
https://martenframework.com
MIT License
424 stars 24 forks source link

Add support for template fragment caching #89

Closed ellmetha closed 1 year ago

ellmetha commented 1 year ago

Description

Now that low-level caching capabilities were added to the framework (as part of #61), one interesting feature to add would be the ability to perform template fragment caching.

To do that, a new cache template tag should be included. This template tag should require at least two arguments (a key and an expiry value in seconds), and should allow to cache the rendered content corresponding to the template content within the cache tag block:

{% cache "key" 600 %}
  Cached content
{% endcache %}

Additionally, it should be possible to specify additional positional arguments in order to "complement" the key used for the cache with dynamic template variable values. For example:

{% cache "key" 600 locale user.id %}
  Cached content
{% endcache %}