torchbox / django-pattern-library

UI pattern libraries for Django templates
https://torchbox.github.io/django-pattern-library/
BSD 3-Clause "New" or "Revised" License
360 stars 44 forks source link

Add a no-op cache tag #245

Open bcdickinson opened 5 months ago

bcdickinson commented 5 months ago

Is your proposal related to a problem?

Cache-related template tag's like Django's {% cache %} and Wagtail's {% wagtailcache %} and {% wagtailpagecache %} work by attempting to render a cached fragment, falling back to rendering the child nodes and storing the result in the cache.

When viewing patterns in the pattern library, particularly during local development, this is not what you want. You want to be able to instantly view changes made to the template. Additionally, context required to generate cache keys, such as page.cache_key in the case of {% wagtailpagecache %} may not be present in the pattern library context.

Describe the solution you'd like

I propose the DPL should have a no-op tag that unconditionally renders it's children and the ability to specify by name the tags that should be replaced with the no-op tag implementation in pattern library contexts. Config for this might look something like the following:

PATTERN_LIBRARY = {
    ...,
    "NOOP_CACHE_TAG_NAMES": ["cache", "wagtailcache", "wagtailpagecache"],
}

Maybe ["cache"] should be the default value for this?