function cacheResponse(key, value, duration) {
        let redis = globalOptions.redisClient;
        let expireCallback = globalOptions.events.expire;

        if (redis && redis.connected) {
            try {
                redis.hset(key, "response", JSON.stringify(value));
                redis.hset(key, "duration", duration);
                redis.expire(key, duration / 1000, expireCallback || function () {});
            } catch (err) {
                debug("[apicache] error in redis.hset()");
            }
        } else {
            memCache.add(key, value, duration, expireCallback);
        }

        // add automatic cache clearing from duration, includes max limit on setTimeout
        timers[key] = setTimeout(function () {
            instance.clear(key, true);
        }, Math.min(duration, 2147483647));
    }
Sets a cache value for the given key.
@param {string} key The cache key to set.
@param {any} value The cache value to set.
@param {number} duration How long in milliseconds the cached
response should be valid for (defaults to 1 hour).

Generated by Trelent