diff --git a/.changeset/breezy-crabs-yell.md b/.changeset/breezy-crabs-yell.md new file mode 100644 index 0000000000..d06235e625 --- /dev/null +++ b/.changeset/breezy-crabs-yell.md @@ -0,0 +1,5 @@ +--- +'@directus/api': patch +--- + +Reverted cache-control header change to prevent cache inconsistencies in-app diff --git a/api/src/utils/get-cache-headers.test.ts b/api/src/utils/get-cache-headers.test.ts index 92642f6f2c..9eeadee1f4 100644 --- a/api/src/utils/get-cache-headers.test.ts +++ b/api/src/utils/get-cache-headers.test.ts @@ -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', diff --git a/api/src/utils/get-cache-headers.ts b/api/src/utils/get-cache-headers.ts index ae254fdf41..98838382df 100644 --- a/api/src/utils/get-cache-headers.ts +++ b/api/src/utils/get-cache-headers.ts @@ -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