Updated cached-fragment-tag based on new raptor-cache module

This commit is contained in:
Patrick Steele-Idem 2014-08-08 16:35:47 -06:00
parent e1e735a43a
commit 9768afe255

View File

@ -1,20 +1,29 @@
'use strict';
var FRAGMENT_CACHE_CONFIG = {
store: 'memory'
};
var raptorCache;
var defaultCacheManager;
var req = require; // Fool the raptor-optimizer
module.exports = {
render: function (input, context) {
if (raptorCache === undefined) {
try {
raptorCache = require('raptor-cache');
raptorCache = req('raptor-cache');
}
catch(e) {
throw new Error('The "raptor-cache" module should be installed as an application-level dependency when using caching tags');
}
defaultCacheManager = raptorCache.createCacheManager({
profiles: {
'*': {
'raptor-templates/cached-fragment': {
store: 'memory',
encoding: 'utf8'
}
}
}
});
}
var cacheKey = input.cacheKey;
@ -22,10 +31,9 @@ module.exports = {
throw new Error('cache-key is required for <cached-fragment>');
}
// use the default cache manager
var cacheManager = raptorCache.getDefaultCacheManager(context);
var cacheManager = input.cacheManager || defaultCacheManager;
var cache = cacheManager.getCacheByName(input.cacheName, FRAGMENT_CACHE_CONFIG);
var cache = cacheManager.getCache(input.cacheName || 'raptor-templates/cached-fragment');
var asyncContext = context.beginAsync();