cache API alternatives

One drawback of using KV for the cache is that there is no easy way to purge that cache. With the current approach by using Cache API we put a custom Cache-Tag to a response, let's say category name. And then once we update pages in that category we call CF API to purge cache by that cache tag. There might be a million pages in that category, so we just purge by cache tag and no need to purge cache for each page. Maybe I didn't completely get the idea of the approach used in worker sites (https://blog.cloudflare.com/extending-the-workers-platform/) but looks like it doesn't fit our use case as we can't update millions of pages in KV. I thought maybe we can have different KV namespaces per each category, so when we need to purge the cache - recreate the namespace. There is a limit of 100 namespaces and we might have thousands of categories. With R2 there is the same cache purge issue + it doesn't support keys expiration as we have in KV
The Cloudflare Blog
Workers Sites: Extending the Workers platform with our own serverle...
As of today, with the Wrangler CLI, you can now deploy entire websites directly to Cloudflare Workers and Workers KV.
3 Replies
vvotekeb
vvotekeb•2y ago
does anyone know how we can purge cache if using KV as a cache? is there some way to remove all keys (millions) from KV (and it's cache) that contains a specific prefix? or maybe it's more easy to achieve the same with R2?
Cyb3r-Jak3
Cyb3r-Jak3•2y ago
You would have to list all the keys then delete each key. You can write keys that expire as well which don't count as an operation
vvotekeb
vvotekeb•2y ago
the content that we want to cache in KV may change any time (actually few times a week, with a release, some bug fix, new feature) yes, we can list the keys and then delete them but there is no batch delete 😦 so we will end up with millions of delete operations
Want results from more Discord servers?
Add your server