Kirby Time Cache - v0.2


#1

Github: https://github.com/jenstornell/kirby-partial-cache

I needed a simple way to use partial cache and at the same time have an expire time for the cached blocks.

I started out with a great little script made by @bnomei, which then became a good inspiration for this plugin: Cache part of a page? Thank you, I added you as a contributor in the repo.

Anyway, it’s really simple:

It will write “Hello world” on the screen and the second time it will load it from a cached file, if the expire time is not reached.

Expire time can be set as an option or an argument, default is 1 day

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

You can find more advanced examples in the repo.

Features

  • Cache anything you want.
  • Set the expire time as config option or as argument.
  • Set the cache folder to anything you like.
  • Hash the cache filename or not, the choice is yours.
  • Debug the cached blocks by using a HTML comment before and after.
  • Multiple instances. Multiple cache files, for multiple blocks, with different expire times.

#2

@jenstornell Man! You really love making plugins. :slight_smile:

Forgive me but can you please give a real world example why this is useful?


#3

In my case I update one of my sites with a part in the sidebar. That part is really slow because it get 30K products and kind of group them by categories.

One idea could be to use the Kirby cache for this, but I want to keep the rest of the content fresh. That sidebar part will not update very often so it’s ok if it’s only updated 1 time every day.

Most of the site now use a database and less of the site uses Kirby pages.

So it can be useful if a part of a site is really slow and you have reasons to not use the Kirby cache.


#4

Version 0.2 released!

Github: https://github.com/jenstornell/kirby-time-cache

Yes, I’ve changed the name from Kirby Partial Cache to Kirby Time Cache, because it’s not just for parts anymore.

I’ve been thinking a long time if I should continue the development of this plugin or not. Kirby 3 will probably be released this year and it makes uncertain of which plugins that will still be relevant in the future.

I’ve decided that this plugin will still have a place, now and in the future. Instead of shutting it down, I’ve improved it.

Caches full pages - With a refresh after a time expire

The biggest change with this version is that it caches full pages, similar to the built in cache. The difference is that it expires after a time of your choice. It’s especially good when you for example use a database where Kirby does not know when the content has been updated.

0.2

  • Changed name from Kirby Partial Cache to Kirby Time Cache.
  • New feature - Full pages caching.
  • Bug fix with filenames without dots.
  • Added new option time.cache.path, the path where the cache files will be stored.
  • Added new option time.cache.pages, to enable/disable caching of full pages.
  • Added new option time.cache.pages.expire, which is the expire time of cached pages.
  • Added new option time.cache.pages.comments, to enable/disable html comments of cached pages.
  • Removed site option ``.
  • Removed the options partial.cache.before, partial.cache.after and partial.cache.comments.
  • Changed license to MIT.