mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
32 lines
1.2 KiB
JavaScript
32 lines
1.2 KiB
JavaScript
'use strict';
|
|
module.exports = {
|
|
render: function (input, context) {
|
|
var attributes = context.attributes;
|
|
var cacheProvider = attributes.cacheProvider;
|
|
var cache;
|
|
var cachedHtml;
|
|
var cacheKey = input.cacheKey;
|
|
if (!cacheKey) {
|
|
throw require('raptor').createError(new Error('cache-key is required for <caching:cached-fragment>'));
|
|
}
|
|
if (!cacheProvider) {
|
|
var raptorCacheModulePath;
|
|
try {
|
|
raptorCacheModulePath = require.resolve('raptor-cache');
|
|
}
|
|
catch(e) {
|
|
throw new Error('The "raptor-cache" module should be installed as an application-level dependency when using caching tags');
|
|
}
|
|
cacheProvider = require(raptorCacheModulePath).getDefaultProvider();
|
|
}
|
|
cache = cacheProvider.getCache(input.cacheName);
|
|
cachedHtml = cache.get(cacheKey, function () {
|
|
return context.captureString(function () {
|
|
if (input.invokeBody) {
|
|
input.invokeBody();
|
|
}
|
|
});
|
|
});
|
|
context.write(cachedHtml);
|
|
}
|
|
}; |