1. Go to this page and download the library: Download bnomei/kirby3-boost library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bnomei / kirby3-boost example snippets
class DefaultPage extends \Kirby\Cms\Page
{
use \Bnomei\ModelHasBoost;
}
// fill cache
$count = site()->boost();
echo $count . ' Pages have been boosted.';
class AdminUser extends \Kirby\Cms\User
{
use \Bnomei\ModelHasBoost;
}
Kirby::plugin('myplugin/user', [
'userModels' => [
'admin' => AdminUser::class, // admin is default role
],
]);
// in full site index
$allPagesWithTemplatePost = site()->searchForTemplate('post');
// starting with blog as parent
$pagesWithTemplatePostInBlog = page('blog')->searchForTemplate('post');
// write content cache of a single page
$cachedYesOrNoAsBoolean = $page->boost();
// write content cache of all pages in a Pages collection
$durationOfThisCacheIO = $page->children()->boost();
// write content cache of all pages in site index
$durationOfThisCacheIO = site()->boost();
// use helpers to generate caches to compare
// rough performance level is based on my tests
$caches = [
// better
// \Bnomei\BoostCache::null(),
// \Bnomei\BoostCache::memory(),
\Bnomei\BoostCache::php(), // 142
\Bnomei\BoostCache::apcu(), // 118
\Bnomei\BoostCache::sqlite(), // 60
\Bnomei\BoostCache::redis(), // 57
// \Bnomei\BoostCache::file(), // 44
\Bnomei\BoostCache::memcached(), // 11
// \Bnomei\BoostCache::mysql(), // ??
// worse
];
// run the cachediver benchmark
var_dump(\Bnomei\CacheBenchmark::run($caches, 1, 1000)); // a rough guess
var_dump(\Bnomei\CacheBenchmark::run($caches, 1, site()->index()->count())); // more realistic
return [
// other options
// like Pages or UUID Cache
// cache type for each plugin you use like the Laspe plugin
// default is file cache driver because it will always work
// but performance is not great so set to something else please
'bnomei.boost.cache' => [
'type' => 'file',
],
// example php
'bnomei.boost.cache' => [
'type' => 'php',
],
'cache' => [
'uuid' => [
'type' => 'php',
],
],
// example apcu
'bnomei.boost.cache' => [
'type' => 'apcu',
],
'cache' => [
'uuid' => [
'type' => 'apcu',
],
],
// example apcu with garbage collection
'bnomei.boost.cache' => [
'type' => 'apcugc',
],
'cache' => [
'uuid' => [
'type' => 'apcugc',
],
],
// example sqlite
// https://github.com/bnomei/kirby3-sqlite-cachedriver
'bnomei.boost.cache' => [
'type' => 'sqlite',
],
'cache' => [
'uuid' => [
'type' => 'sqlite',
],
],
// example redis
// https://github.com/bnomei/kirby3-redis-cachedriver
'bnomei.boost.cache' => [
'type' => 'redis',
'host' => function() { return env('REDIS_HOST'); },
'port' => function() { return env('REDIS_PORT'); },
'database' => function() { return env('REDIS_DATABASE'); },
'password' => function() { return env('REDIS_PASSWORD'); },
],
'cache' => [
'uuid' => [
// do same as boost
],
],
// example memcached
'bnomei.boost.cache' => [
'type' => 'memcached',
'host' => '127.0.0.1',
'port' => 11211,
],
'cache' => [
'uuid' => [
// do same as boost
],
],
];
// this can be skipped on next benchmark
site()->boost();