@amazon/vinyl-cache-manager
v1.1.1
Published
A mediator for the Cache API
Downloads
434
Readme
@amazon/vinyl-cache-manager
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-managerUsage
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
