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
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.