You can enable Kirby's page cache in your
config.php file with the
The page cache files are stored in the
||Either an array of page IDs to ignore, or a callback function that returns a boolean|
Not all page responses can and will be cached. Kirby automatically determines whether a response is cacheable.
- Only the base response of a page is cached. If the request matches any of the following criteria, the response is not cached:
- If the request contains a query string, request data or a Kirby param
- If the request uses a HTTP method other than
- If the page is excluded from caching via the
ignoreoption or a page model, the page is never cached.
- If the response relies on
$kirby->session(), a cookie value (
Cookie::get()) or the
$kirby->request()->auth()), Kirby protects against sharing the cache between visitors who have these values set and those who don't. In particular, Kirby behaves like this:
- If any of the queried request headers is set, the response is considered private and never cached.
- If the headers are not set in the current request, the response is cached but the cached response is only used for requests without these headers. This ensures that users with the cookie or authentication receive their own personalized response.
If your template code or a plugin you use rely on cookies or authentication but don't use Kirby's built-in methods, Kirby cannot automatically detect the usage. In this case, please call
$kirby->response()->usesAuth(true) respectively. You don't need to do this if you use Kirby's methods from the list above.
If you want to create your own cache instance, you can just add it to the config like this:
That's it! Now you got a new cache up and running with the id
This will again be a file cache instance and stores the cache files in
You have the same extended options if needed and you can combine different cache types without hassle.
As soon as you configured your cache in the config, you can start using it like this (for example in a controller):
You can define how long a cache variable is valid by specifying the number of minutes until it expires in the set method:
The getter will now return
null after the 30 minutes expired.
Plugins can have their own namespaced caches by defining them in their options:
This plugin cache instance will be available at:
But you can even have multiple cache instances per plugin:
Following the same concept, you can access it like this: