function makeResponseCacheable(req, res, next, key, duration, strDuration, toggle) {
    // monkeypatch res.end to create cache object
        res._apicache = {
            write: res.write,
            writeHead: res.writeHead,
            end: res.end,
            cacheable: true,
            content: undefined,
        };

        // append header overwrites if applicable
        Object.keys(globalOptions.headers).forEach(function (name) {
            res.setHeader(name, globalOptions.headers[name]);
        });

        res.writeHead = function () {
            // add cache control headers
            if (!globalOptions.headers["cache-control"]) {
                if (shouldCacheResponse(req, res, toggle)) {
                    res.setHeader("cache-control", "max-age=" + (duration / 1000).toFixed(0));
                } else {
                    res.setHeader("cache-control", "no-cache, no-store, must-revalidate");
                }
            }

            res._apicache.headers = Object.assign({}, getSafeHeaders(res));
            return res._apicache.writeHead.apply(this, arguments);
        };

        // patch res.write
        res.write = function (content) {
            accumulateContent(res, content);
            return res._apicache.write.apply(this, arguments);
        };

        // patch res.end
        res.end = function (content, encoding) {
            if (shouldCacheResponse(req, res, toggle)) {
                accumulateContent(res, content);

                if (res._apicache.cacheable && res._apicache.content) {
                    addIndexEntries(key, req);
                    let headers = res._apicache.headers || getSafeHeaders(res);
                    let cacheObject = createCacheObject(
                        res.statusCode,
                        headers,
                        res._apicache.content,
                        encoding
                    );
                    cacheResponse(key, cacheObject, duration);

                    // display log entry
                    let elapsed = new Date() - req.apicacheTimer;
                    debug("adding cache entry for \"" + key + "\" @ " + strDuration, logDuration(elapsed));
                    debug("_apicache.headers: ", res._apicache.headers);
                    debug("res.getHeaders(): ", getSafeHeaders(res));
                    debug("cacheObject: ", cacheObject);
                }
            }

            return res._apicache.end.apply(this, arguments);
        };

        next();
    }
Monkeypatches the response object to add cache control headers
and create a cache object.
@param {Object} req Express request object
@param {Object} res Express response object
@param {function} next Function to call next
@param {string} key Key to add response as
@param {number} duration Time to cache response for
@param {string} strDuration Duration in string form
@param {function(Object, Object):boolean} toggle