Skip to content

Kirby 6.0.0

$responder->cache()

Setter and getter for the flag that defines whether the current response can be cached by Kirby's cache

$responder->cache(bool|null $cache = null): bool|Responder

Parameters

Name Type Default
$cache boolornull null

Return types

boolorKirby\Cms\Responder

This method does not modify the existing $responder object but returns a new object with the changes applied. Learn more →

Parent class

Kirby\Cms\Responder

Examples

return function ($kirby, $page) {
  $random = null;
  if ($page->randomize()->toBool()) {
    $random = random_int(1, 10);

    // prevent Kirby from caching this response;
    $kirby->response()->cache(false);
  }

  return compact('random');
};