Rest API Cache in Kirby v3


Can you point me in the right direction? — I am not sure if the docs give me enough information…
How would I cache a kirby rest api call on my own site?
Is something easy like

‘cache’ => [
‘api’ => [
‘active’ => true

How would I then clean the cache after a page is updated? — I was thinking about hooking into page.update:after with cache->remove($key), but what would be the $key for an API call?



From the docs:

1: Set up a custom cache “api” in your config.php like this:

return [
  'cache.api' => true

2: Use your cache

// e.g. in a controller
return function ($kirby) {

  $apiCache = $kirby->cache('api');
  $apiData  = $apiCache->get('apiData');

  // there's nothing in the cache, so let's fetch it
  if ($apiData === null) {
    $apiData = Remote::get('');
    $apiCache->set('apiData', $apiData);

  return compact('apiData');


Now there’s a cached version of the returned API data in your “api”-cache under the “apiData”-key.

So if you’ld like to remove the cached apiData from your “api”-cache, you’ld have to do it like $apiCache->remove('apiData').

1 Like

its a good answer, because it clarifies my question, although it does not solve it.
What you posted is found in the docs and is clear to me.

What I mean, on the other side, is a cache for the internal rest api:
If there is something pre-build or if I have to build it on my own (Maybe hooking into route: and page.update:?), maybe somebody has a code snippet?


i do not know of any cache for the core api. but maybe @rasteiner or @rbnschlz know some hidden gems since they do a lot api stuff.

Oh, I’m sorry. I missed that you were referring to Kirby’s own API.

I don’t know if there’s anything built-in tbh. But if there isn’t, I think you should be able to get around that by setting it up as in the docs and consuming the site’s own API (instead of an external API)?

that would make it public. the core api is protected by authentification.

are there any new information about it?
We should cache the api calls because we have built an react frontend with kirby as the cms. We have a lot of traffic and we do not want to send the from the frontend… this is a huge security issue, if you don’t protect the panel.