mmikkel / CacheFlag-Craft

Flag and clear template caches
MIT License
36 stars 5 forks source link

Feature request: ability to delete caches flagged with any user-enterred flag in CP #12

Closed benface closed 7 years ago

benface commented 7 years ago

First of all, thank you for the great plugin, it's been very helpful! I have an idea for a new feature if you don't mind.

A use case for this feature would be having something like this in a layout/base template:

{% cacheflag flagged 'header' globally using key craft.request.path %}
    <header>
        ...
    </header>
{% endcacheflag %}

Say you want to modify the <header> HTML; unfortunately Craft won't automatically purge the cache because using key is used. From Craft's documentation:

If you change the template code within a {% cache %} that uses a custom key, any existing template caches will not automatically be purged. You will either need to assign the tag a new key, or clear your existing template caches manually using the Clear Caches tool in Settings.

It suggests two alternatives, but:

  1. Changing the key every time the HTML changes is not practical.
  2. "Clear Caches" clears ALL the template caches.

Hence my feature request. I imagine it being a "Clear Caches With Given Flag" button that opens a modal asking which flag(s) should be targeted.

Feel free to say no if you don't think this is a good idea or if it's too much work. Thanks!

mmikkel commented 7 years ago

Hi @benface, thanks for contributing.

It's already possible to clear individual, flagged caches in Cache Flag's CP section. What you're suggesting would basically be the same thing, only more accessible/easier to use. It'd certainly be useful, but unfortunately I can't promise I'll find the time to add something like this anytime soon.

benface commented 7 years ago

Oh I see what you mean! Do you have to "Save all flags" before you can "Empty caches"?

mmikkel commented 7 years ago

Not really, but the individual Empty caches button will only be enabled if a) the corresponding flag has in fact been saved, and 2) there are in fact relevant caches to clear for any particular flag.

benface commented 7 years ago

Thank you, that is more than good enough for me. I don't need this feature anymore, so feel free to close it unless you think it's worth adding. :)