I am creating posts for my plugins to make it easier to find them using the forum search and not just the docs search.
Boost the speed of Kirby by having content files of pages cached, with automatic unique ID, fast lookup and Tiny-URL.
up to 3x faster content loading
fastest page lookup and resolution of relations
If you have to process within a single request a lot of page objects (1000+) or if you have a lot of relations between page objects to resolve then consider using this plugin. With less page objects you will propably not gain enough to justify the overhead.
How does this plugin work?
It caches all content files and keeps the cache up to date when you add or modify content. This cache will be used when constructing page objects making everything that involves page objects faster (even the Panel).
It provides a benchmark to help you decide which cachedriver to use.
It can add an unique ID for page objects that can be used create relations that do not break even if the slug or directory of a page object changes.
It provides a very fast lookup for page objects via id, diruri or the unique id.
It provides you with a tiny-url for page objects that have an unique id.
class DefaultPage extends \Kirby\Cms\Page
class DefaultPage extends \Bnomei\BoostPage
// page lookup
$page = page($somePageId); // slower
$page = boost($somePageId); // faster
$page = boost($somePageDirUri); // fastest
$page = boost($boostId); // will use fastest internally
// resolving one relation
$pageOrNull = $page->one_relation()->fromBoostID();
// resolving many relations
$pagesCollectionOrNull = $page->many_related()->fromBoostIDs();
A cache driver is a piece of code that defines where get/set commands for the key/value store of the cache are directed to. Kirby has built in support for File, Apcu, Memcached and Memory. I have created additional cache drivers for MySQL , Redis and SQLite.
// other options
// example apcu
'bnomei.boost.cache' => [
'type' => 'apcu',
I created an interactive demo to compare various cache drivers and prove how much your website can be boosted. It kind of ended up as a love-letter to the KQL Plugin as well. You can find the benchmark and interactive demos running on server sponsored by Kirbyzone here:
Hi @bnomei, thanks for another great plugin. I wanted to use the included Benchmark on a production server to decide which driver to use, but was unable to perform the test. Maybe I forgot some configs, but I couldn’t figure it out.
you do not need real pages to run the CacheBenchmark. but that is only a quick way to compare some caches. like the readme says you should verify real performance lateron using the boostmark() pages method as well. for example on my demo server the redis driver ranks 4th place in the generic benchmark but 2nd place when using the boostmark with real page objects.
the only situation for the array to come up emtpy would be that the drivers are not available as far as i can tell right now. so maybe var_dump the $caches array and see if there are objects in there or just null values.
ah yeah, i hadn’t configured the caches correctly. thanks for the hint.
unfortunately, i am unable to activate APCu and Memcached on the production server due to limitations (it’s a managed server). will there be support for the OPcache with the boost plugin? that would be great.
yes. once you have a page boosted accessing any content field will be faster since the initial load was made from cache.
in your example the title will be loaded the same time as the boostid. but that load will be from cache and thus faster than from disk.
it does not however reduce computational load like from using site->find or site->index. you would need to create a statically cached collection/sitemethod for these. static because it might be called by kirby more than once in a single request. i will publish a short example later.
The new version 1.9.0 add support for content caching of files and users. So if you have to read the content files of many of them then do consider using the Boost plugin to speed up the load time up to 3-4x times.
I update my boost plugin demo server to most recent version of kirby and kql. also moved it to a “slow” 5 euro/month hetzner instance to better show how much the plugins speeds up content loading.
the main demo page shows a general read/write benchmark for caches but that needs to be taken with a grain of salt since when using them with boost there are lots of initial writes (using transactions to batch them) when indexing and later on there are just a massive amount of read calls. some caches like sqlite and redis really excel at read speeds. https://kirby3-boost.bnomei.com/
the subdomains each show a cache driver like apcu, redis, sqlite, mysql and php. the null cache driver is kind of special and at the same time not… it simply is running no cache at all. use this to compare how much faster things get using boost and a cache driver.
read 5500 pages in one request => earthlings
php: 2500ms (that loads all 38k pages of the demo since its a mono cache file)
kirby actually has to load more than 5500 with all parent pages in the tree.
read 20.000 pages in one request => karma of humans
php: 22.000ms (not sure why thats slow actually, will check it out, should be around 14-17sec)
mysql: > 30.000ms (thats 20k or more queries, no optimization yet)
with lots of pages the performed computations of the demo take up a major part of the response time. the null driver performs well enough here but thats partly due to boost resolving the page uuids to page objects and not the core logic (see toPagesBoosted).
summary: as long as the read speed of your cache is faster than reading from files you gain some performance boost.