Quicktip: Fine-tuning cache settings
Control caching from a blueprint option or a field
Cache options are set via the
config.php file. To prevent caching for certain pages, we can use the
ignore option and either provide a list of page IDs to be ignored, or a callback function that returns a boolean for more control.
However, we can use this callback to make excluding pages from the cache much more dynamic without having to return to the
config file every time we made some changes that require the cache settings to be adapted.
In our blueprint, we add a
cache option like this:
title: Blueprint title options: cache: false
In our config file, we can now check if the
cache option is set or not and return the negated value or default to
While the above solution provides flexibility for developers, this is usually out of the control of editors and does not apply to single pages but to entire page types (i.e. pages sharing the same blueprint).
However, using a similar concept, we can leave it to the editor to decide whether or not to cache a page by adding a toggle (or checkbox field) to the page blueprint.
title: Blueprint title fields: cache: type: toggle default: false text: Exclude from cache?
config.php, we now query the field value:
Thanks to Markus Denhoff for sharing the idea with the blueprint option.