mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Updated cached-fragment-tag based on new raptor-cache module
This commit is contained in:
parent
e1e735a43a
commit
9768afe255
@ -1,31 +1,39 @@
|
||||
'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;
|
||||
if (!cacheKey) {
|
||||
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();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user