Skip to content

Export CacheOverride API for cross-platform cache control #82

@trieloff

Description

@trieloff

Background

Per adobe/helix-deploy-plugin-edge#77 and comment, @adobe/fetch should export a CacheOverride API that provides cross-platform cache control for both Fastly Compute and Cloudflare Workers.

Proposal

Export a CacheOverride class/object that:

  • On Fastly: Uses native fastly:cache-override module
  • On Cloudflare: Maps to cf.cacheTtl, cf.cacheKey, cf.cacheTtlByStatus options

Common Options

  • Mode: "none", "pass", "override"
  • TTL: Time-to-live in seconds
  • SWR: Stale-while-revalidate (Fastly only, graceful degradation on Cloudflare)
  • Cache Key: Custom cache key string
  • Surrogate Key: For cache purging (Fastly only, maps to cf.cacheTags on Cloudflare)

Usage

import { fetch, CacheOverride } from '@adobe/fetch';

const cacheOverride = new CacheOverride('override', { 
  ttl: 3600,
  swr: 86400 
});

const response = await fetch(url, { cacheOverride });

Platform Mapping

Feature Fastly Cloudflare
Mode: pass cacheOverride mode cf.cacheTtl: 0
TTL ttl option cf.cacheTtl
SWR swr option Not supported
Cache Key cacheKey in CacheOverride cf.cacheKey
Surrogate Key surrogateKey option cf.cacheTags

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions