feat: support cache expiration & improve admin speed
- 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
}
})
Deploying playground with
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 |
I think something in this just broke this: https://github.com/nuxt-hub/core/issues/316