Kirby3 Boost - makes loading a lot of pages in one request fast + unique ID

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

Usecase

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.

site/blueprints/pages/default.yml

preset: page

fields:
  # visible field
  boostid:
    type: boostid
  
  # hidden field
  #boostid:
  #  extends: fields/boostid

  one_relation:
    extends: fields/boostidpage

  many_related:
    extends: fields/boostidpages

site/models/default.php

class DefaultPage extends \Kirby\Cms\Page
{
    use \Bnomei\PageHasBoost;
}

// or

class DefaultPage extends \Bnomei\BoostPage
{
    
}

PHP

// 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();

Cache Drivers

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.

site/config/config.php

<?php

return [
    // other options

    // example apcu
    'bnomei.boost.cache' => [
        'type'     => 'apcu',
    ],
];

Interactive Demo

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: