Replace ASSETS_CACHE_CONTROL with ASSETS_CACHE_TTL

This commit is contained in:
rijkvanzanten
2020-12-16 14:47:15 -05:00
parent f228996799
commit bfb2df432e
4 changed files with 7 additions and 7 deletions

View File

@@ -55,7 +55,7 @@ CACHE_NAMESPACE="directus-cache"
CACHE_STORE=memory # memory | redis | memcache
CACHE_AUTO_PURGE=true
ASSETS_CACHE_CONTROL="max-age=604800"
ASSETS_CACHE_TTL="30m"
# CACHE_REDIS="redis://:authpassword@127.0.0.1:6380/4"
# --OR--

View File

@@ -10,6 +10,7 @@ import storage from '../storage';
import { PayloadService, AssetsService } from '../services';
import useCollection from '../middleware/use-collection';
import env from '../env';
import ms from 'ms';
const router = Router();
@@ -112,7 +113,8 @@ router.get(
res.removeHeader('Content-Disposition');
}
res.setHeader('Cache-Control', env.ASSETS_CACHE_CONTROL);
const access = !!req.accountability?.role ? 'private' : 'public';
res.setHeader('Cache-Control', `${access}, max-age="${ms(env.ASSETS_CACHE_TTL as string)}"`);
stream.pipe(res);
})
);

View File

@@ -34,6 +34,7 @@ const defaults: Record<string, any> = {
CACHE_TTL: '30m',
CACHE_NAMESPACE: 'system-cache',
CACHE_AUTO_PURGE: false,
ASSETS_CACHE_TTL: '30m',
OAUTH_PROVIDERS: '',
@@ -45,8 +46,6 @@ const defaults: Record<string, any> = {
EMAIL_SENDMAIL_PATH: '/usr/sbin/sendmail',
TELEMETRY: true,
ASSETS_CACHE_CONTROL: 'public, max-age=604800',
};
let env: Record<string, any> = {

View File

@@ -211,10 +211,9 @@ Controls whether or not the cache will be auto-purged on create/update/delete ac
feature means that the API will remain real-time, while caching subsequent read calls when no changes have happened.
**Note**: enabling auto-purge will remove the `Cache-Control` header, as the cache can be invalidated at any point.
### `ASSETS_CACHE_CONTROL`
### `ASSETS_CACHE_TTL`
The value for the `Cache-Control` header for the static assets in the /assets endpoint. Defaults to
`public, max-age=604800`.
How long assets will be cached for in the browser. Sets the `max-age` value of the `Cache-Control` header.
## File Storage