core icon indicating copy to clipboard operation
core copied to clipboard

feat: support cache expiration & improve admin speed

Open atinux opened this issue 1 year ago • 2 comments

  • resolves #213
  • resolves #306

By having our own nuxthub unstorage driver , we can now

  • The cache entry metadata in KV metadata
  • Set the expiration of the item so Cloudflare will remove it automatically (works in development too!)

The Cache admin dashboard is now much faster for new cache entries as it will read the metadata from the list instead of fetching the cache entry for each item 🚀

I also updated the module to always run the Cloudflare platform proxy in development, this is needed for storing the cache in local KV as it support expiration and bring consistency with production. Also, we don't support (and won't) remote storage for cache entries for performance reasons.

This brings a powerful feature from Cloudflare as we can now access event.context.cf from the server and API routes:

export default eventHandler(event => {
  export default eventHandler(async (event) => {
  const { isEUCountry, continent, city, timezone, country, region, latitude, longitude, botManagement } = event.context.cf
  return {
    continent,
    isEUCountry,
    country,
    region,
    city,
    timezone,
    latitude,
    longitude,
    botManagement
  }
})

atinux avatar Oct 09 '24 23:10 atinux

Open in Stackblitz

pnpm add https://pkg.pr.new/nuxt-hub/core/@nuxthub/core@313

commit: ff14a0e

pkg-pr-new[bot] avatar Oct 09 '24 23:10 pkg-pr-new[bot]

Deploying playground with  Cloudflare Pages  Cloudflare Pages

Latest commit: ff14a0e
Status: ✅  Deploy successful!
Preview URL: https://4833154c.playground-bhb.pages.dev
Branch Preview URL: https://feat-cache-speed.playground-bhb.pages.dev

View logs

I think something in this just broke this: https://github.com/nuxt-hub/core/issues/316

robert-hoffmann avatar Oct 11 '24 21:10 robert-hoffmann