deploy_feedback icon indicating copy to clipboard operation
deploy_feedback copied to clipboard

Add a edge cache layer

Open neves opened this issue 4 years ago • 4 comments

Like Vercel does https://vercel.com/docs/serverless-functions/edge-caching#stale-while-revalidate Is there a plan to add a edge cache layer in front of deno deploy?

neves avatar Jul 30 '21 13:07 neves

It's on our roadmap but there's no ETA yet.

bnoordhuis avatar Aug 01 '21 11:08 bnoordhuis

Would it make sense for now then to just put a separate cdn cache layer in front of deno deploy, like fastly?

osdiab avatar Sep 08 '22 06:09 osdiab

Hi guys! I'm really looking forwards this feature.

Adding my two cents here, we could leverage from the Web Cache API. Suppose we have the following code:

const CACHE = await caches.open("v1");

const handler = (req: Request) => {
      const stale = await CACHE.match(req)
      
      if (stale) return stale
      
      const fresh = generateResponseSomehow()
      
      CACHE.put(req, fresh.clone())
      
      return fresh
}

I would love if the one isolate running this code performs a put on the cache, all other isolates (in the same region) can read from the same cache and return the same stale content. This would be even better than a stale CDN like Vercel, since this would allow us to vary the asset being delivered by a custom logic I could write in my Deno code without sacrificing performance. For instance, this could solve many issues with Deno's Fresh, where one JS asset is built multiple times (one for each isolate instance). Also, this could open possibilities like transforming images on the go inside Deno and spreading the result across multiple isolates.

tlgimenes avatar May 22 '23 17:05 tlgimenes

Coming from a Cloudflare user (and previously a devrel there), a key point is whether or not cache items replicate across regions.

In Cloudflare Workers, cached contents don't leave the originating data center. This was very unclear for a long time, historically. But now that this is known & documented (🙋‍♂), a nasty side effect is that devs have to manually wrangle with cache invalidations...across all regions where stale values may exist... because Cache Purge doesn't affect the Cache API layer that Workers manipulate.

So, two key takeaways here for Deno Deploy, whether or not you choose to replicate Cache contents:

  1. Be clear (and honest) about how/if it works
  2. Add a Dashboard tool and/or API endpoint that programmatically wipes a Cache key from all regions

lukeed avatar Apr 24 '24 16:04 lukeed