Amazon Vinyl logo Amazon Vinyl v3.2.1

@amazon/vinyl-cache-manager

Website npm size

A small mediator over the browser Cache API that adds HTTP-style cache-control semantics: TTLs, stale-while-revalidate, only-if-cached, custom cache keys, and validation hooks. Designed to be shared between the application and a service worker, with no runtime dependencies.

Install

npm install @amazon/vinyl-cache-manager

Usage

import { CacheManager } from '@amazon/vinyl-cache-manager'

const cache = new CacheManager({ name: 'media' })

const response = await cache.get('https://example.com/segment.m4s', {
    cacheControlDefaults: { maxAge: 60 },
    cacheControlOverrides: { staleWhileRevalidate: 24 * 60 * 60 },
})

cacheControlDefaults apply when the response carries no Cache-Control, cacheControlOverrides always win when reading from cache. POST requests can be cached by passing an explicit cacheKey.

License

Apache-2.0