arunsathiya / portfolio

Arun's blog posts and portfolio of software projects, powered by Notion as a CMS
https://www.arun.blog
2 stars 1 forks source link

Cache signed asset URLs in Cloudflare Workers KV Storage #76

Closed arunsathiya closed 2 months ago

arunsathiya commented 2 months ago

I think there is scope is improving performance by caching signed asset URLs in Cloudflare Workers KV Storage and reading from it, rather than having to generate a new signed URL on each visit by every visitor.

arunsathiya commented 2 months ago

For example, images in a blog post seem to take ~770ms each, could shave off a lot of that processing time by caching on Workers KV Storage:

image
arunsathiya commented 2 months ago

Implemented in https://github.com/arunsathiya/portfolio-workers/commit/226d5418468b604388cbe09f5c1b0428e2508c49. I think it works:

npx wrangler tail

 ⛅️ wrangler 3.73.0
-------------------

Successfully created tail, expires at 2024-09-02T10:19:52Z
Connected to portfolio-workers, waiting for logs...
GET https://www.arun.blog/cdn/blog/assets/private-among-us-games-on-the-tailscale-network-039db48d-d183-45f4-b9e7-a52ca42cdbd0.png - Ok @ 9/1/2024, 9:51:33 PM
  (log) Key: blog/assets/private-among-us-games-on-the-tailscale-network-039db48d-d183-45f4-b9e7-a52ca42cdbd0.png
  (log) Used cached signed URL for blog/assets/private-among-us-games-on-the-tailscale-network-039db48d-d183-45f4-b9e7-a52ca42cdbd0.png