UNPKG

671 BJavaScriptView Raw
1'use strict';
2
3module.exports = function getCacheExpiryGenerator (opts) {
4
5 /**
6 * Get the expiry for a response. It might be just the default, but we also
7 * support custom expiry length for certain status codes.
8 *
9 * By default a non 200 status is not cached (return 0)
10 *
11 * @param {String} statusCode
12 * @return {Number}
13 */
14 return function getCacheExpiry (statusCode) {
15 if (statusCode === 200) {
16 return (
17 opts.statusCodeExpires && opts.statusCodeExpires[statusCode] ||
18 opts.expeditious.getDefaultTtl()
19 );
20 } else {
21 return opts.statusCodeExpires && opts.statusCodeExpires[statusCode] || 0;
22 }
23 };
24
25};