Skip to content

@emdash-cms/cloudflare@0.22.0

Choose a tag to compare

@emdashbot emdashbot released this 22 Jun 19:26
6b036c4

Minor Changes

  • #1378 640e60a Thanks @scottbuscemi! - Add an optional distributed object cache for query results.

    Content reads (getEmDashCollection, getEmDashEntry, resolveEmDashPath) and chrome reads (site settings, menus, taxonomies) can now be served from a fast key/value store instead of hitting the database on every request. This sits beneath the per-request cache and above the database, dramatically reducing read pressure on D1/SQLite — especially valuable on Cloudflare, where KV handles far more requests than D1.

    The cache is off by default and fully opt-in. Configure a backend in astro.config.mjs:

    import { kvCache } from "@emdash-cms/cloudflare"; // Workers KV (distributed)
    import { memoryCache } from "emdash/astro"; // in-isolate (Node / local dev)
    
    emdash({
    	database: d1({ binding: "DB" }),
    	objectCache: kvCache({ binding: "CACHE" }),
    });

    with a matching KV binding in wrangler.jsonc:

    { "kv_namespaces": [{ "binding": "CACHE", "id": "<namespace-id>" }] }

    Invalidation is epoch-based and automatic: content, byline, taxonomy, menu, and settings writes bump a per-namespace version, instantly orphaning stale entries (no key enumeration needed). Preview and visual-edit requests bypass the cache, so editors previewing see live content; other reads are served from the cache, which only ever stores published content. After an edit, anonymous visitors may see stale content until isolates pick up the bumped epoch — immediate on the in-isolate memory backend, and on KV bounded by KV's edge-cache propagation (eventually consistent, up to ~60s) plus the revalidate window (default 1s, configurable).

    New public API: cachedQuery, invalidateObjectCache, invalidateCollectionCache, contentNamespace/contentNamespaces, CacheNamespace, the ObjectCache* types (from emdash), memoryCache() (from emdash/astro), and kvCache() (from @emdash-cms/cloudflare). Existing sites are unaffected until they opt in.

  • #1549 a623c6b Thanks @ascorbic! - Fixes responsive image optimization for storage-backed media on Cloudflare. EmDash now wraps Astro's image endpoint to read media bytes directly from your storage adapter instead of fetching them over HTTP, so Image and Portable Text images generate a real responsive srcset even when the site is behind Cloudflare Access (previously these 404'd and fell back to a full-size image). This is on by default and also removes an internal HTTP round-trip on Node. Set images: false in your emdash() config to leave Astro's image endpoint untouched.

Patch Changes