Kirby3 PHP Cache-Driver
Elephant - a highly performant PHP Cache Driver for Kirby 3
Support open source!
This plugin is free but if you use it in a commercial project please consider to sponsor me or make a donation.
If my work helped you to make some cash it seems fair to me that I might get a little reward as well, right?
Be kind. Share a little. Thanks.
|Github sponsor||Patreon||Buy Me a Coffee||Paypal dontation||Buy a Kirby license using this affiliate link|
- unzip master.zip as folder
git submodule add https://github.com/bnomei/kirby3-php-cachedriver.git site/plugins/kirby3-php-cachedriveror
composer require bnomei/kirby3-php-cachedriver
$cache = \Bnomei\PHPCache::singleton(); // or $cache = elephant(); $cache->set('key', 'value', $expireInMinutes); $value = elephant()->get('key', $default); elephant()->remove('key'); elephant()->flush();
Mono or multile files
bnomei.php-cachedriver.mono (default: true) setting you can change if the cache driver uses a single or multiple files to store the cached data. In either case all files will be loaded so there is no gain here. But when writing data the behaviour is different.
In the mono-mode all data is written at the end of the php skript life-cycle. This does not count against your script execution time but for example when you change value in the cache with each request writing that big file everytime the time might prove inefficient. If the data in your cache changes very rarely or a lot use this behaviour.
When storing the data in one file per cache key then writing to the cache happens right when calling
$cache->set(). This means you only write small changes and fast but it counts towards your max script execution time. This behaviour is well suited when a small amount of data changes often.
php : 0.03383207321167 file : 2.3811981678009
ATTENTION: This will create and remove a lot of cache files and php-cache files
No cache when debugging
When Kirbys global debug config is set to
true the complete plugin cache will be flushed and no caches will be read. But entries will be created. This will make you live easier – trust me.
How to use Elephant with Lapse or Boost
You need to set the cache driver for the lapse plugin to
return [ 'bnomei.lapse.cache' => ['type' => 'php'], 'bnomei.boost.cache' => ['type' => 'php'], //... other options ];
Setup Content-File Cache
Use Kirby 3 Boost to setup a cache for content files.
||use a single file instead of one for each key|
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.