src/cache.ts

This is where the caching rules are defined for both Layer0 (edge) and the browser.

By default, this file exports two caching constants:

cache.ts
const ONE_HOUR = 60 * 60
const ONE_DAY = 24 * ONE_HOUR

export const CACHE_PAGES = {
  // Caching pages configuration on the edge
  edge: {
    // Store the cache on the edge for an hour
    maxAgeSeconds: ONE_HOUR,
    // Use this flag to cache pages regardless of their cache-control header
    forcePrivateCaching: true,
  },
  // Caching pages configuration in the browser
  browser: {
    // Do not store the cache on the browser (which is to not rely on browser's default caching mechanism)
    maxAgeSeconds: 0, 
    // Store the cache on the browser through Layer0 service worker for an hour
    // All requests to such pages when made while navigation will be directly served from the service worker
    // Also, as pages are prefetched, the service worker caches them for an hour inside the browser, and serves it directly from the browser cache
    serviceWorkerSeconds: ONE_HOUR,
  },
}

export const CACHE_PAGES = {
  // Caching pages configuration on the edge
  edge: {
    // Store the cache on the edge for a day
    maxAgeSeconds: ONE_DAY,
    // Use this flag to cache pages regardless of their cache-control header
    forcePrivateCaching: true,
  },
  // Caching pages configuration in the browser
  browser: {
    // Do not store the cache on the browser (which is to not rely on browser's default caching mechanism)
    maxAgeSeconds: 0, 
    // Store the cache on the browser through Layer0 service worker for a day
    // All requests to such pages when made while navigation will be directly served from the service worker
    // Also, as pages are prefetched, the service worker caches them for a day inside the browser, and serves it directly from the browser cache
    serviceWorkerSeconds: ONE_DAY,
  },
}
Edit this page on GitHub Updated at Tue, Jun 21, 2022