Cache part of a page?

You can use the cache class to cache the data you parsed from the blueprint (this code belongs in a controller):

$data = cache::get('cachekey');
if(!$data) {
  // get data somehow
  $data = somefunction();
  
  // cache it
  cache::set('cachekey', $data);
}

return compact('data');

Please note that you need to enable the cache so that Kirby can store the data in the site/cache directory. You could however use c::set('cache.ignore', ['*']); to disable the page cache.

5 Likes