Skip to content

Latest commit

 

History

History
87 lines (53 loc) · 2.63 KB

readme.md

File metadata and controls

87 lines (53 loc) · 2.63 KB

Kirby Time Cache

Version License Donate

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.

Table of contents

Usage

Cache pages

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.

Cache part - Basic

Use it in a template or a snippet like this:

echo time::cache('filename.json', function() {
    return 'Hello world!';
});

Cache part - Advanced

$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.

Requirements

Disclaimer

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.

License

MIT

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.

Credits