diff --git a/.env.example b/.env.example index ccd8b08c..0582fff3 100644 --- a/.env.example +++ b/.env.example @@ -3,6 +3,9 @@ PUBLIC_API_URL="" PUBLIC_API_VERSION="v4" +# Disable API browser cache interceptor globally (true for local development) +PUBLIC_DISABLE_CACHE=false + # OAuth # An OAuth client must exist for this web app in the v4 API instance # The client should allow the grants: `authorization_code`, `refresh_token`, `password` diff --git a/src/openapi/cacheFetch.ts b/src/openapi/cacheFetch.ts index 4f4db40a..ff3c1d73 100644 --- a/src/openapi/cacheFetch.ts +++ b/src/openapi/cacheFetch.ts @@ -53,6 +53,9 @@ function isStaleCache(cached: Response, defaultMaxAgeMs: number = DEFAULT_MAX_AG export function createBrowserCacheInterceptor(cacheName: string = CACHE_NAME) { return async (request: Request, opts: RequestOptions): Promise => { + if (import.meta.env.PUBLIC_DISABLE_CACHE === "true") { + return request; + } const originalFetch = opts.fetch ?? globalThis.fetch; opts.fetch = async (req: Request) => { diff --git a/src/openapi/cacheInterceptor.ts b/src/openapi/cacheInterceptor.ts index caa44d63..d6f17076 100644 --- a/src/openapi/cacheInterceptor.ts +++ b/src/openapi/cacheInterceptor.ts @@ -13,6 +13,9 @@ export function getCacheInterceptorId() { } export function initCacheInterceptor() { + if (import.meta.env.PUBLIC_DISABLE_CACHE === "true") { + return null; + } _interceptor = createBrowserCacheInterceptor(); _interceptorId = client.interceptors.request.use(_interceptor); return _interceptorId;