Skip to main content

Web Cache

@svendowideit/web-cachev2026.10.23.1· MIT(was none)· 1d agoBEHAVIORSWORKFLOWS
01README

A managed, disk-backed HTTP GET cache — the single place responses are fetched, cached, paced, and retried, so other models read the cache instead of re-implementing (and re-hitting) the network. WHAT IT DOES

Turns repeated HTTP GETs into cached reads. Every response is stored on disk — the raw body plus the full set of response headers — keyed deterministically by URL, and a repeated call returns the cached copy without touching the network unless the entry is missing, explicitly bypassed, or stale. Prefer it over ad-hoc curl calls in every model: origin requests are paced with a minimum delay persisted across runs, HTTP 429s are retried with backoff, and each call's new fetches are capped, so bulk work stays within the origin's rate limits and a large backlog drains across runs. The cache key depends only on the URL, so any model that knows a URL can share the same cache directory.

INSTALL

swamp extension pull @svendowideit/web-cache

DEPENDENCIES

None — it uses Deno's built-in fetch and the bundled deno binary that swamp already ships. No other extension is required, and nothing is installed on the host.

RUN

# Fetch a URL (raw body) and cache it.
swamp model @svendowideit/web-cache method run get cache \
  --input url="https://en.wikipedia.org/w/api.php?action=opensearch&search=Alfred+Bester&limit=5&format=json"

# Fetch many URLs in one call, capping new origin fetches at 20
# (cached hits don't count).
swamp model @svendowideit/web-cache method run get-many cache \
  --input 'urls:json=["https://example.org/a.json","https://example.org/b.json"]' \
  --input maxFetches=20

# Inspect the cache: size, age, freshness, stored headers.
swamp model @svendowideit/web-cache method run cache-info cache

CONFIGURE

All arguments are optional global arguments (set at model creation with --global-arg key=value):

cacheDir            Where responses are cached       (default ~/.swamp/web-cache)
userAgent           User-Agent header                (default swamp-web-cache/1.0)
defaultMaxAgeMs     Freshness window; 0 = always     (default 0)
                    prefer cache
requestDelayMs      Minimum delay between origin     (default 1000)
                    requests (persisted across runs)
retryDelayMs        Wait after a 429 before retry     (default 5000)
maxRetries          Retries after a 429               (default 1)
maxFetchesPerCall   Cap on origin fetches per call   (default 100)
acceptHeader        Accept header sent               (default application/json)

Per-run overrides: url, forceRefresh, and maxAgeMs on get/get-json; urls, maxFetches, forceRefresh on get-many; url/all on invalidate. See the README for the full method and data reference.

WHAT IT INSTALLS

Nothing on the host — no services, daemons, cron triggers, or webhooks. It reads and writes a local cache directory (cacheDir) and writes swamp resources.

02Behaviors1
@svendowideit/web-cachev2026.10.23.1web_cache.ts

Global Arguments

ArgumentTypeDescription
cacheDir?stringDirectory to cache fetched responses under
userAgent?stringUser-Agent header sent with requests
defaultMaxAgeMs?numberDefault freshness window for cached responses (0 = always prefer the
requestDelayMs?numberMinimum delay between origin requests (across runs, persisted in the
retryDelayMs?numberWait this long after a 429 rate-limit before a retry (the origin's
maxRetries?numberNumber of retries after a 429 (backing off each time).
acceptHeader?stringAccept header sent with requests
maxFetchesPerCall?numberMaximum number of *origin* fetches (network requests) a single get/get-many
fn get()
Fetch a URL and return its raw body (UTF-8). Cached on disk;
fn get-json()
Fetch a URL and return its body parsed as JSON. Cached on disk.
fn get-many(urls: array, maxFetches?: number)
Fetch many URLs in one method call, caching each independently.
ArgumentTypeDescription
urlsarrayURLs to fetch (each cached independently). Empty strings are skipped,
maxFetches?numberCap on the number of origin fetches this call makes (omit = use global
fn invalidate(key?: string, url?: string)
Drop cached entries. Pass a `key` (see cache-info) to drop one entry,
ArgumentTypeDescription
key?stringCache key to drop (see cache-info). Omit to clear everything.
url?stringAlternative: drop the cache entry for this URL
fn cache-info(key?: string)
Report cache state. Pass a `key` to inspect a single entry (including
ArgumentTypeDescription
key?stringInspect a single cache entry; omit for a whole-cache summary

Resources

fetch(infinite)— Result of a get (raw body, headers, cache state)
json(infinite)— Result of a get-json (parsed JSON, cache state)
batch(infinite)— Summary of a get-many call (counts + whether the fetch cap truncated it)
cache(infinite)— Cache inspection / invalidation result
03Workflows1
@svendowideit/web-cache-fetch74f4482a-830a-4b78-a99d-691f70ba4e73

Fetch a list of URLs through the shared disk cache. This is the single place any workflow goes to pull an external URL: it prefers the cached copy, paces origin requests, retries 429s, and caps origin fetches per call so a backlog drains across runs. Returns nothing domain-specific — callers read the cached bodies themselves (or via their own domain model's parse methods). Inputs: urls — array of URLs to fetch (empty strings are skipped/deduped) maxFetches — cap on origin fetches this

mainFetch + cache the requested URLs.
1.get-many— Fetch each URL through the disk cache (paced, retried, capped).
04Previous Versions3
2026.09.25.1
2026.09.20.4

Modified 1 behaviors. Added 1 workflows

2026.09.20.3
05Stats
A
100 / 100
Downloads
40
Archive size
19.0 KB
  • Has README or module doc2/2earned
  • README has a code example1/1earned
  • README is substantive1/1earned
  • Most symbols documented1/1earned
  • No slow types (deprecated)1/1earned
  • Dependencies pass trust audit2/2earned
  • Has description1/1earned
  • Platform support declared (or universal)2/2earned
  • License2/2earned
  • Verified public repository2/2earned
06Platforms