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