kinetex - v1.0.0-rc.1
    Preparing search index...

    Class HTTPCache

    RFC 7234-compliant HTTP cache with LRU eviction, Vary support, stale-while-revalidate, stale-if-error, tag-based invalidation, and pluggable storage backends.

    const cache = new HTTPCache({ maxEntries: 200, defaultTtlMs: 30_000 });
    await cache.set(req, res);
    const result = await cache.get(req);
    Index

    Constructors

    Methods

    • Look up a cached response.

      Parameters

      • req: CacheableRequest

      Returns Promise<{ entry: CacheEntry; stale: boolean } | null>

      An object with entry (the cached CacheEntry) and stale (boolean indicating the entry is expired but within the stale-while-revalidate or stale-if-error window), or null if no matching entry was found.

    • Store a response in the cache.

      Parameters

      • req: CacheableRequest

        The request used as the cache key

      • res: CacheableResponse

        The response to cache

      • options: { tags?: string[]; ttlMs?: number; force?: boolean } = {}

        Optional tags, per-entry TTL override, or force flag to bypass no-store

      Returns Promise<boolean>

      true if the entry was stored, false if rejected (uncacheable, too large, or quota exceeded)

    • Build conditional request headers (If-None-Match / If-Modified-Since) for cache revalidation.

      Parameters

      Returns Record<string, string>

    • Handle a 304 Not Modified response — refresh the entry TTL in place.

      Parameters

      • req: CacheableRequest
      • res: CacheableResponse

      Returns Promise<CacheEntry | null>

    • Mark a request as being revalidated for stale-while-revalidate. Returns false if the key is already in flight.

      Parameters

      • req: CacheableRequest

      Returns Promise<boolean>

    • Clear the SWR in-flight flag for a request.

      Parameters

      • req: CacheableRequest

      Returns Promise<void>

    • Check whether a request is currently being revalidated.

      Parameters

      • req: CacheableRequest

      Returns Promise<boolean>

    • Delete a single entry from the cache.

      Parameters

      • req: CacheableRequest

      Returns Promise<boolean>

      true if the entry existed and was deleted

    • Delete all entries whose URLs start with a given prefix. Works with namespaces.

      Parameters

      • urlPrefix: string

      Returns Promise<number>

    • Delete all entries with a specific tag.

      Parameters

      • tag: string

      Returns Promise<number>

    • Clear all cached entries.

      Returns Promise<void>

    • Pre-populate the cache with a set of request/response pairs.

      Parameters

      • entries: { req: CacheableRequest; res: CacheableResponse; tags?: string[] }[]

      Returns Promise<void>

    • Reset all cache statistics to zero.

      Returns void

    • Serialize cache entries to a JSON string for persistence. Expired entries are excluded. Format: { version: 1, entries: [[key, entry], ...] }.

      Returns Promise<string>

    • Restore cache entries from a previously serialized JSON string. Validates structure, enforces max age and body size limits, skips expired entries.

      Parameters

      • data: string

      Returns Promise<void>

      If the JSON format is invalid or unexpected.