for kirbys base cache class a function called remember could be added that makes the common usecase of only fetching a value from cache if its null easier. this is done using a simple closure.
basically thats the main idea for my lapse plugin as well (with some more magic for the key generator).
https://github.com/bnomei/kirby3-lapse
$data = lapse(crc32($page->url()), function () use ($kirby, $site, $page) {
// create some data
return [
'author' => site()->author(),
'title' => $page->title(),
'text' => $page->text()->kirbytext(),
'url' => $page->url(),
];
});
can be closed as implemented:
https://getkirby.com/docs/reference/objects/cache/cache/get-or-set