export async function getReverseProxyResponseFetchCacheApi(request: Request, requestRules: RequestRules, pageProviderUrl: string): Promise<Response> {
const useCache = SecurityService.isBusinessIpRequest(request);
const cacheKey = CacheKeyService.getCacheKey(request, pageProviderUrl);
let page = await fetch(pageProviderUrl, {
cf: {
cacheTtl: useCache ? requestRules.reverseProxyTtl : undefined,
cacheTtlByStatus: {
'300-599': 0,
},
cacheKey: cacheKey,
cacheTags: [CacheKeyService.getCacheTags(request, requestRules)],
},
});
page = new Response(page.body, page);
// Cache-Control is completely ignored by the tiered cache since we provided a TTL
const cacheControl = page.headers.get('cache-control');
// If the cache is not public, or set to no-store, don't cache
if (!page.ok || (cacheControl && (!cacheControl.includes('public') || cacheControl.includes('no-store')))) {
// How do we handle this?
// await caches.default.delete(cacheKey);
return page;
}
return page;
}
export async function getReverseProxyResponseFetchCacheApi(request: Request, requestRules: RequestRules, pageProviderUrl: string): Promise<Response> {
const useCache = SecurityService.isBusinessIpRequest(request);
const cacheKey = CacheKeyService.getCacheKey(request, pageProviderUrl);
let page = await fetch(pageProviderUrl, {
cf: {
cacheTtl: useCache ? requestRules.reverseProxyTtl : undefined,
cacheTtlByStatus: {
'300-599': 0,
},
cacheKey: cacheKey,
cacheTags: [CacheKeyService.getCacheTags(request, requestRules)],
},
});
page = new Response(page.body, page);
// Cache-Control is completely ignored by the tiered cache since we provided a TTL
const cacheControl = page.headers.get('cache-control');
// If the cache is not public, or set to no-store, don't cache
if (!page.ok || (cacheControl && (!cacheControl.includes('public') || cacheControl.includes('no-store')))) {
// How do we handle this?
// await caches.default.delete(cacheKey);
return page;
}
return page;
}