ah unfortunately that specific implementation is not open sourced currently, but its basically this

ah unfortunately that specific implementation is not open sourced currently, but its basically this for checking using the cache api:
  const cfCache = await platform.caches.open("(cache name here)");

  const cacheMatch = await cfCache.match(cacheURL) as Response | undefined;
  if(cacheMatch) {

    const responseGeneratedRaw = cacheMatch.headers.get("x-response-generated");

    if(responseGeneratedRaw) {
      const responseGenerated = new Date(responseGeneratedRaw);

      if(Date.now() - responseGenerated.getTime() < cache_time) {
        // return data from cache match
      }
    }
  }

and for storing the response in the cache api:
platform?.context?.waitUntil(
  cfCache.put(cacheURL, await createMFResponse(jsonResponse.clone()) as Response)
)

theres some conversion stuff there because miniflare's response object doesnt match the web api, but you might not have to deal with that depending on what youre doing
Was this page helpful?