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';
|
'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();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user