UNPKG

566 BJavaScriptView Raw
1'use strict';
2
3/**
4 * Determines if the current request is a candidate for caching.
5 * By default only GET requests will be cached.
6 * @param {IncomingRequest} req
7 * @return {Boolean}
8 */
9module.exports = function getShouldCache (opts) {
10 var customCache = opts.shouldCache;
11
12 return function shouldCache (req) {
13 if (customCache) {
14 // Developer wants to override default caching rules
15 return customCache(req);
16 } else {
17 // Default behaviour is to cache on GET requests only
18 return 'GET' === req.method.toUpperCase();
19 }
20 };
21};