Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Set s-maxage for shared cache on shot images. (#3591)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenba committed Oct 12, 2017
1 parent 380bcd1 commit 76fe5b0
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions server/src/caching.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
const config = require("./config").getProperties();

const tenMinutesInSeconds = 10 * 60;
const aDayInSeconds = 24 * 60 * 60;
exports.cacheTime = 60 * 60 * 24 * 30; // 30 days

if (!config.setCache) {
exports.cacheTime = 0;
}

function createCacheSetter(cacheLength) {
function createCacheSetter(maxAge, flags) {
return function(res, options) {
if (config.setCache && cacheLength) {
if (config.setCache && maxAge) {
let vals = [];
options = options || {};

let pub = options.private ? "private" : "public";
res.set("Cache-Control", `${pub}, max-age=${cacheLength}`);
vals.push(pub);
vals.push(`max-age=${maxAge}`)

if (flags) {
vals = vals.concat(flags);
}

res.set("Cache-Control", vals.join(', '));
} else {
res.set("Cache-Control", "no-cache");
}
}
}

exports.setMonthlyCache = createCacheSetter(exports.cacheTime);
exports.setDailyCache = createCacheSetter(aDayInSeconds);
exports.setDailyCache = createCacheSetter(aDayInSeconds, `s-maxage=${tenMinutesInSeconds}`);

0 comments on commit 76fe5b0

Please sign in to comment.