Caching
Caching pages
You can enable Kirby's page cache in your config.php
file with the cache.pages
option:
The page cache files are stored in the /site/cache
folder.
Page requests will only be cached if there are no params in the URL.
Options
Option | Value |
---|---|
active |
true /false |
ignore |
Either an array of page IDs to ignore, or a callback function that returns a boolean |
Excluding pages using a page model
If you need even more detailed control over which pages are cached or ignored, you can use page models with an override of the $page->isCacheable()
method:
Cache drivers and options
Using a different cache driver
Set up your own cache
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 api
.
This will again be a file cache instance and stores the cache files in /site/cache/api
.
You have the same extended options if needed and you can combine different cache types without hassle.
Using the cache
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.
Plugin caches
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: