Skip to main content

@rtorcato/cf-common

Interfaces​

CachePutOptions​

Defined in: index.ts:18

Properties​

ttl?​

optional ttl?: number

Defined in: index.ts:20

Seconds the entry stays fresh (sets Cache-Control: max-age).


CacheStore​

Defined in: index.ts:24

A thin view over one Cache instance with TTL support.

Methods​

match()​

match(key): Promise<Response | undefined>

Defined in: index.ts:25

Parameters​
key​

string | Request<unknown, CfProperties<unknown>>

Returns​

Promise<Response | undefined>

put()​

put(key, response, options?): Promise<void>

Defined in: index.ts:26

Parameters​
key​

string | Request<unknown, CfProperties<unknown>>

response​

Response

options?​

CachePutOptions

Returns​

Promise<void>

delete()​

delete(key): Promise<boolean>

Defined in: index.ts:27

Parameters​
key​

string | Request<unknown, CfProperties<unknown>>

Returns​

Promise<boolean>

Functions​

buildCacheKey()​

buildCacheKey(url, params?): Request

Defined in: index.ts:9

Build a stable cache-key Request from a URL and optional query params. The Cache API only keys on GET requests with absolute URLs; params are sorted so {a,b} and {b,a} hit the same entry.

Example​

const key = buildCacheKey('https://cache.internal/users', { id: 7 })

Parameters​

url​

string | URL

params?​

Record<string, string | number | boolean> = {}

Returns​

Request


createCache()​

createCache(cache): CacheStore

Defined in: index.ts:39

Wrap a Cache (e.g. caches.default or await caches.open('name')). put clones nothing: pass a fresh Response, or .clone() it first if you also return it to the client.

Example​

const cache = createCache(caches.default)
await cache.put(buildCacheKey(url), res.clone(), { ttl: 300 })

Parameters​

cache​

Cache

Returns​

CacheStore