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
]
]
available?
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?
// 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('https://someapi.com');
$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').
Hey,
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: https://getkirby.com/docs/reference/api/pages
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?
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)?
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.