• Try to return a response from cache

    • if {ifNoneMatch: true} is set, we are passing ETag value from cache response to the request 'if-none-match' header for data validation.
    • if {ifMatch: true} is set, we are passing ETag value from cache response to the request 'if-match' header for data validation.

    Parameters

    • req: RequestInfo | URL

      RequestInfo | URL to match

    • Optionaloptions: CacheOptions & CacheQueryOptions

      optional CacheQueryOptions and CacheOptions

    • cacheName: string = 'default'

      name of the cache to match (default: 'default')

    Returns Promise<Response | undefined>

    Response or undefined

    const req = new Request('http://localhost:3000/api/v1/health');
    const cacheRes = await cacheMatch(req, {ifNoneMatch: true}); // ifNoneMatch: 'if-none-match' header from cached response ETag
    const res = await fetch(req);
    if (res.status === 304) { // 304 Not Modified
    // use cached response

    v0.0.1