Options
All
  • Public
  • Public/Protected
  • All
Menu

Stores and retrieves Response objects.

see

withCache()

see

asDataCache()

example
const store = stores.indexedDB({store: 'my-objects'});
const ignore = () => {};

export const cache = {
async get(request) {
return await store.get(request.url).catch(ignore);
},
async set(request, response) {
return await store.set(request.url, response).catch(ignore);
}
}

Hierarchy

  • Cache

Index

Methods

Methods

  • Retrieves a Response object from the cache. You should resolve with undefined if the cached value is not found, expired, or invalid. Do NOT reject the returned Promise.

    example
    const store = stores.indexedDB({store: 'my-objects'});
    const ignore = () => {};

    export const cache = {
    async get(request) {
    return await store.get(request.url).catch(ignore);
    },
    async set(request, response) {
    return await store.set(request.url, response).catch(ignore);
    }
    }

    Parameters

    • request: Request

      Contains information you can use to create a cache key. Typically, the url is unique enough to act as a key. See the example code.

    Returns Promise<Response>

    Promise resolved with undefined if the key could not be found in the cache or is invalid; otherwise, resolved with the Response object passed to Cache.set.

  • Stores a Response object in the cache. Resolve the returned promise when the object has been cached OR if the caching operation fails. Do NOT reject the returned Promise.

    example
    const store = stores.indexedDB({store: 'my-objects'});
    const ignore = () => {};

    export const cache = {
    async get(request) {
    return await store.get(request.url).catch(ignore);
    },
    async set(request, response) {
    return await store.set(request.url, response).catch(ignore);
    }
    }

    Parameters

    • request: Request

      Contains information you can use to create a cache key. Typically, the url is unique enough to act as a key. See the example code.

    • response: Response

      The Response to cache. This is the value that should be returned from Cache.get.

    Returns Promise<void>

    A promise resolved when the value is cached.