mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
42 lines
999 B
JavaScript
42 lines
999 B
JavaScript
var caches = {};
|
|
|
|
function createCache() {
|
|
var cache = {};
|
|
|
|
return {
|
|
get: function(cacheKey, options, callback) {
|
|
setTimeout(function() {
|
|
var value = cache[cacheKey];
|
|
if (value !== undefined) {
|
|
return callback(null, value);
|
|
}
|
|
|
|
var builder = options.builder;
|
|
builder(function(err, value) {
|
|
if (err) {
|
|
return callback(err);
|
|
}
|
|
|
|
if (value === undefined) {
|
|
value = null;
|
|
}
|
|
|
|
cache[cacheKey] = value;
|
|
|
|
callback(null, 'myCacheManager:' + value);
|
|
});
|
|
}, 10);
|
|
}
|
|
};
|
|
}
|
|
|
|
var myCacheManager = {
|
|
getCache: function(cacheName) {
|
|
return caches[cacheName] || (caches[cacheName] = createCache());
|
|
}
|
|
};
|
|
|
|
exports.templateData = {
|
|
myCacheManager: myCacheManager
|
|
};
|