A cache that expires after a time of your choice.
Features
- Cache pages similar to the built in cache.
- Cache part of a page or a function.
- Set an expire time, as config option or as argument.
This cache will cache pages similar to the built in cache. The difference is that it will expire after a time of your choice. It's expecially good for sites that use a database where Kirby does not know when the content has been updated.
You need to add this to your config:
c::set('time.cache.pages', true);
That's it! You pages should now be cached!
To see id
, filename
and timestamp
in the cached HTML code, you can also add this option:
c::set('time.cache.pages.comments', true);
You can't add the last option after the page has already been cached. Then you need to remove the cache file or wait for the cache to expire and refresh itself.
Use it in a template or a snippet like this:
echo time::cache('filename.json', function() {
return 'Hello world!';
});
$page = page('about');
$site = site();
echo time::cache('filename.json', function() use ($page, $site) {
return $page->title() . ' - ' . $site->title();
}, 60);
Use arguments
It uses $page
and $site
that then become available inside the time::cache
function. You can use any variables you want.
Time expire
It also has the third argument 60
which is the expire time. It will refresh the cache in 1 minute (60 seconds). You can also set the expire time globally with the c::set('time.cache.expires')
option.
- Kirby 2.5+
This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.
It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.