sheercms
Version:
Sheer Cliff CMS is a simple and powerful content management system (CMS) for Node JS.
84 lines (77 loc) • 1.72 kB
JavaScript
var api = require('../api');
var logger = require('../logger');
/*
callback: (err)
*/
module.exports.set = function(key, value, seconds, callback) {
if (key) {
var cache = api.plugins.get("cache");
if (cache) {
cache.set(key, value, seconds, callback);
}
else {
if (callback) callback(null);
}
}
else {
if (callback) callback(null);
}
};
/*
key: if null, then the cache is not checked.
callback: (err, value)
*/
module.exports.get = function(key, callback) {
if (callback) {
if (key) {
var cache = api.plugins.get("cache");
if (cache) {
cache.get(key, callback);
}
else
callback(null, null);
}
else {
callback(null, null);
}
}
};
/*
callback: (err)
*/
module.exports.remove = function(key, callback) {
logger.info("Removing cache key: " + key);
var cache = api.plugins.get("cache");
if (cache) {
cache.remove(key, callback);
}
else {
if (callback) callback(null);
}
};
/*
callback: (err)
*/
module.exports.removeAll = function(prefix, callback) {
logger.info("Removing all cache with prefix: " + prefix);
var cache = api.plugins.get("cache");
if (cache) {
cache.removeAll(prefix, callback);
}
else {
if (callback) callback(null);
}
};
/*
callback: (err, count)
*/
module.exports.count = function(callback) {
logger.info("Counting cache items");
var cache = api.plugins.get("cache");
if (cache) {
cache.count(callback);
}
else {
if (callback) callback(null, 0);
}
};