1. Go to this page and download the library: Download bnomei/kirby3-lapse 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-lapse example snippets
$key = hash('xxh3', $page->url()); // unique key
// to delay data creation until need use a callback. do not use a plain array or object.
$data = function () {
return [1, 2, 3];
};
$data = lapse($key, $data);
Kirby::plugin('bnomei/example', [
'collections' => [
// collections have to be a closure that is why it is wrapped in a fn
'recent-courses' => fn() => lapseStatic(
'recent-courses', // key
function () { // value
return page('courses')->children()->listed()->sortBy('name')->limit(10);
}
)
]);
// lapse v1 could already do this:
// store data until objects are modified with optional expire
$data = lapse(
$page->id().$page->modified(),
['some', 'kind', 'of', 'data'],
60*24*7 // one week
);
// now it can create magic cache keys from kirby objects
$data = lapse(
$page, // key with modification date created by lapse based on object
function () use ($page) {
return [
'title' => $page->title(),
];
}
);
// or from an collection of pages or files
$collection = collection('mycollection');
$data = lapse(
$collection, // this will turn into a key taking modification date of all objects into consideration
function () use ($collection) {
return [ /*...*/ ];
}
);
// or from an array combining all these
$data = lapse(
['myhash', $page, $page->children()->images(), $collection, $site], // will create key from array of objects
function () use ($site, $page, $collection) {
return [
// will not break serialization => automatically store ->value() of fields
'author' => $site->author(),
'title' => $page->title(),
'hero' => $page->children()->images()->first()->srcset()->html(),
'count' => $collection->count(),
];
}
);
// remove by dynamic key
$wasRemoved = \Bnomei\Lapse::rm(
['myhash', $page, $page->children()->images(), $collection, $site]
);
$data = lapse(
$page,
function () use ($page) {
if ($page->isUnpublished()) {
// do not cache unpublished pages
throw new \Bnomei\LapseCancelException();
}
return $page->title()->value();
}
);
// $data === null for unpublished pages
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.