Skip to content

$responder->cache()

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

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

Parameters

Name Type Default
$cache bool null

Return type

bool|Kirby\Cms\Responder

This method modifies the existing $responder object it is applied to and returns it again.

Parent class

Kirby\Cms\Responder

Example

<?php

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');
};