Replies: 6 comments 5 replies
-
|
Hi there! |
Beta Was this translation helpful? Give feedback.
-
|
Usecase: https://staging.kasperdevos.com/ The backend (build with the kirby-headless starter) is deployed with Ploi on digitalocean. I've adde these to the site's Nginx config: The idea is to catch the queries with a cache everything page-rule. The reason being that I've created a hook in kirby to purge my cache when updating the content. The cache-rule makes the pages load instantly, but when using hydration while navigating to other pages I want the queries to be available from the cache as well. I've tried the KV-storage (as suggested: https://nuxt-kirby.byjohann.dev/guides/caching-strategies.html#server-side-caching), and it works to store the queries. However, I don't seem to be able to revalidate them the same way as with a hook… And I don't like to rely on TTL. The purge-hook works fine though. So i've figured, since the queries are just plain json files, it should also be possible to cache them the same way with the cache-everything page-rule. Does that make sense? |
Beta Was this translation helpful? Give feedback.
-
|
I get it, good idea! Where do you deploy your frontend? During hydration you don't have to worry about the cache, since the server-side query result is written to the payload and received from it during client-side hydration. I don't know how The headers from Kirby are forwarded to Nuxt, so this should not be the issue: nuxt-kirby/src/runtime/server/handler.ts Line 119 in eee5567 |
Beta Was this translation helpful? Give feedback.
-
|
The frontend is deployed to Cloudflare pages ;) Interesting! I've read that POST requests are not cached by default with cloudflare… however, they offer an example code for caching: https://developers.cloudflare.com/workers/examples/cache-post-request/ But I haven't figured out how to implement it with the route as setup with your plugin. In hindsight… kv-storage might be a more solid cache strategy after all… but then I need to figure out how to 'purge' these by a hook instead of relying on TTL… Clients don't like to here that they have to wait for changes to appear. |
Beta Was this translation helpful? Give feedback.
-
|
Interesting! I wasn't aware of the caches feature. That's actually great, since I have the exact same limits you ran into: TTL vs. cache invalidation. Thanks for that article. When deployed to Cloudflare, I might add support for query caching on a worker level in the future. Love that idea. |
Beta Was this translation helpful? Give feedback.
-
|
Yes it is :) I got the idea from a befriended developer who works with sveltekit, but builds his queries as direct get-requests, so He didn't bumb into that post-cache issue. That got me searching when I found that article :) In the meantime I have a follow-up question regarding the kv-storage method. Will it work out of the box when adding it in the config-file? Or should I include the cached key in the queries themself to look for the right queries in the storage? I bet it's already automated the same way the regular the client-side caching works? As a fallback solution I've made an additional file to bulk-delete my kv-storage: I prefer a plain 'bulk deletes' and 'purge everything', since the website's I build don't have many pages and don't change that often. and after a first slow pageload (which is mostly done by the person who updates the cms anyway), the page is freshly cached again :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a way to add a custom header to te received data (response header)? I only seem to be able to add a custom header right after the query inside the composable itself (request header?), but I specifically need to control the header of the received data. I've tried by adding a rule to my ngnix-config (kirby cms) for each api-call '/api/', but that seems to be ignored. Is that due to the way nuxtKql proxies it?
Beta Was this translation helpful? Give feedback.
All reactions