Using KV as a cache in the short term?
I am hooking up my backend to my frontend this weekend and eventually I want to use a service worker for caching.
Until then I was planning on using KV as a cache for specific requests that don't change often. I was looking at the Cache API but since the cache only caches at the originating data center... it seems like KV would be a a better option.
From a strategy perspective... is this a good move? Am I not thinking about something that I should be?
3 Replies
I think this question depends on the cost of the request hitting your origin. KV hot reads are very fast, but they'll only be hot if they've been hit recently, just like the cache API. KV cold reads are probably not going to be faster than your origin, unless your origin is quite slow or really far away.
If the cost of a request hitting your origin are higher than a request at KV costs (factoring in writes to put the data there as well, and storage to have the data stored there), then it seems like a good plan. Otherwise, I don't see much reason to.
Awesome. thanks for that answer. Gave me some good research and and things to think about!
It's also possible to combine the KV Cache with the Cache API. Just check if it's cached and if not load it from the KV. That's the best approach I guess