Skip to content

Commit

Permalink
feat(data): set cache control headers on for stable/unstable data res…
Browse files Browse the repository at this point in the history
…ponse PE-2810

There is some logic in the legacy code base that I'm still thinking
through that this doesn't cover (e.g. zero length responses), but this
handles the common cases.
  • Loading branch information
djwhitt committed Jan 12, 2023
1 parent 28a22d1 commit 0e933d9
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/routes/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
ManifestPathResolver,
} from '../types.js';

const STABLE_MAX_AGE = 60 * 60 * 24 * 30; // 30 days
const UNSTABLE_MAX_AGE = 60 * 60 * 2; // 2 hours
const NOT_FOUND_MAX_AGE = 60; // 1 minute

const DEFAULT_CONTENT_TYPE = 'application/octet-stream';
Expand All @@ -40,8 +42,16 @@ const setDataHeaders = ({
dataAttributes: ContiguousDataAttributes | undefined;
data: ContiguousData;
}) => {
// TODO add cache header(s)
// TODO add etag
// TODO add header indicating stability
// TODO add header indicating whether data is verified
// TODO cached header for zero length data (maybe...)

if (dataAttributes?.stable) {
res.header('Cache-Control', `public, max-age=${STABLE_MAX_AGE}, immutable`);
} else {
res.header('Cache-Control', `public, max-age=${UNSTABLE_MAX_AGE}`);
}

res.contentType(
dataAttributes?.contentType ??
Expand Down

0 comments on commit 0e933d9

Please sign in to comment.