Revert "Don't influence Cache-Control through CACHE_AUTO_PURGE" (#22235)

* Revert "Don't influence Cache-Control through `CACHE_AUTO_PURGE` (#22203)"

This reverts commit 12fb7719fe.

* Add changeset
This commit is contained in:
Rijk van Zanten
2024-04-17 17:01:09 -04:00
committed by GitHub
parent 4bb03df6da
commit be895926ef
3 changed files with 52 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
'@directus/api': patch
---
Reverted cache-control header change to prevent cache inconsistencies in-app

View File

@@ -69,6 +69,50 @@ const scenarios = [
output: 'max-age=0',
},
// Test CACHE_AUTO_PURGE env for no-cache
{
name: 'when CACHE_AUTO_PURGE is true and globalCacheSettings is true',
input: {
env: {
CACHE_AUTO_PURGE: true,
},
headers: {},
accountability: null,
ttl: 5678910,
globalCacheSettings: true,
personalized: false,
},
output: 'no-cache',
},
{
name: 'when CACHE_AUTO_PURGE is true and globalCacheSettings is false',
input: {
env: {
CACHE_AUTO_PURGE: true,
},
headers: {},
accountability: null,
ttl: 5678910,
globalCacheSettings: false,
personalized: false,
},
output: 'max-age=5679',
},
{
name: 'when CACHE_AUTO_PURGE is false and globalCacheSettings is true',
input: {
env: {
CACHE_AUTO_PURGE: false,
},
headers: {},
accountability: null,
ttl: 5678910,
globalCacheSettings: true,
personalized: false,
},
output: 'max-age=5679',
},
// Test personalized
{
name: 'when personalized is true and accountability is null',

View File

@@ -24,6 +24,9 @@ export function getCacheControlHeader(
// When the resource / current request shouldn't be cached
if (ttl === undefined || ttl < 0) return 'no-cache';
// When the API cache can invalidate at any moment
if (globalCacheSettings && env['CACHE_AUTO_PURGE'] === true) return 'no-cache';
const headerValues = [];
// When caching depends on the authentication status of the users