fossasia/loklak_webclient

View on GitHub
iframely/lib/cache-engines/node-cache.js

Summary

Maintainability
A
0 mins
Test Coverage
(function(cache) {

    var NodeCache = require("node-cache");
    var nodeCache = new NodeCache({
        stdTTL: CONFIG.CACHE_TTL,
        checkperiod: CONFIG.CACHE_TTL / 2
    });

    cache.set = function(key, data, options) {
        nodeCache.set(key, data, options && options.ttl || CONFIG.CACHE_TTL);
    };

    cache.get = function(key, cb) {
        nodeCache.get(key, function(error, data) {
            if (error) {
                return cb(null, null);
            }

            if (data && key in data) {
                cb(null, data[key]);
            } else {
                cb(null, null);
            }
        });
    };

})(exports);