Interface IRequestCache

interface for a request cache

const exampleCache: IRequestCache = {
isOnline() {
return (typeof window !== 'undefined' && window.navigator && window.navigator.onLine) || true;
},
async fetchRequest(req: Request) {
if (typeof window !== 'undefined' && window.caches) {
const cache = await window.caches.open('fetch');
return cache.match(req);
}
return undefined;
},
async storeRequest(req: Request, res: Response) {
if (typeof window !== 'undefined' && window.caches && res.ok) {
const cache = await window.caches.open('fetch');
req.headers.delete('Authorization');
await cache.put(req, res.clone());
}
},
};

v0.2.8

interface IRequestCache {
    fetchRequest(req: Request): Promise<undefined | Response>;
    isOnline(): boolean;
    storeRequest(req: Request, res: Response): Promise<void>;
}

Methods

  • get the cached response for a request

    Parameters

    • req: Request

    Returns Promise<undefined | Response>

  • store the response for a request

    Parameters

    • req: Request
    • res: Response

    Returns Promise<void>