How can I prevent the deletion of old KV files when building with Workers?
Hello,
I am building my Vue application using Cloudflare Workers, and I am doing this using Wrangler. The files in the obtained build are stored as KV. The names of my files change according to the build, and when I get a new build, the existing KV values are deleted and replaced with new ones. Since the required files for each loaded page in my application are obtained from the server, users of the application encounter errors when old KVs are deleted.
I think, in order to solve this, the old build files should not be deleted from KV. How can I achieve this?
3 Replies
If you're using Worker Sites, there's an --old-asset-ttl option I've heard of before, I haven't used it before but I assume it simply sets a expirationTtl for the old assets inKV
https://github.com/cloudflare/workers-sdk/pull/3384
GitHub
[wrangler] Add deploy --old-asset-ttl option by Peter-Sparksuite · ...
Fixes #3385
What this PR solves / how to test:
When a wrangler deploy happens, the old assets are immediately deleted, causing users of previously obtained web applications that expect to find spec...
These days though Cloudflare Pages is recommended if you can migrate, free unlimited static requests, versioned deployments, and whatnot:
https://developers.cloudflare.com/pages/migrations/migrating-from-workers/
Pages solves this problem as well with Asset Retention
https://developers.cloudflare.com/pages/platform/serving-pages/
We will insert assets into the cache on a per-data center basis. Assets have a time-to-live (TTL) of one week but can also disappear at any time. If you do a new deploy, the assets could exist in that data center up to one week.
Thank you very much for your help! I think
--old-asset-ttl
is exactly what I'm looking for and I just tested it. Everything seems to be working properly 🎉