use of freemarker.cache.StrongCacheStorage in project freemarker by apache.
the class TemplateLevelSettings method renderWith.
private String renderWith(Version version, String mainBoolFmt, String incBoolFmt, String impBoolFtm) throws IOException, TemplateException {
Configuration cfg = new Configuration(version);
cfg.setTemplateLoader(TEMPLATES);
cfg.setCacheStorage(new StrongCacheStorage());
cfg.setBooleanFormat("C,c");
if (incBoolFmt != null) {
cfg.getTemplate(INCLUDED_FTL).setBooleanFormat(incBoolFmt);
}
if (impBoolFtm != null) {
cfg.getTemplate(IMPORTED_FTL).setBooleanFormat(impBoolFtm);
}
Template t = cfg.getTemplate(MAIN_FTL);
if (mainBoolFmt != null) {
t.setBooleanFormat(mainBoolFmt);
}
StringWriter sw = new StringWriter();
t.process(null, sw);
return sw.toString();
}
use of freemarker.cache.StrongCacheStorage in project freemarker by apache.
the class ConfigurationTest method testChangingTemplateNameFormatClearsCache.
public void testChangingTemplateNameFormatClearsCache() throws Exception {
Configuration cfg = new Configuration();
cfg.setCacheStorage(new StrongCacheStorage());
CacheStorageWithGetSize cache = (CacheStorageWithGetSize) cfg.getCacheStorage();
cache = (CacheStorageWithGetSize) cfg.getCacheStorage();
assertEquals(0, cache.getSize());
cfg.setClassForTemplateLoading(ConfigurationTest.class, "");
assertEquals(0, cache.getSize());
cfg.getTemplate("toCache1.ftl");
assertEquals(1, cache.getSize());
cfg.setTemplateNameFormat(TemplateNameFormat.DEFAULT_2_3_0);
assertEquals(1, cache.getSize());
cfg.setTemplateNameFormat(TemplateNameFormat.DEFAULT_2_4_0);
assertEquals(0, cache.getSize());
cfg.getTemplate("toCache1.ftl");
assertEquals(1, cache.getSize());
cfg.setTemplateNameFormat(TemplateNameFormat.DEFAULT_2_4_0);
assertEquals(1, cache.getSize());
cfg.setTemplateNameFormat(TemplateNameFormat.DEFAULT_2_3_0);
assertEquals(0, cache.getSize());
}
use of freemarker.cache.StrongCacheStorage in project freemarker by apache.
the class ConfigurationTest method testSetTemplateLoaderAndCache.
public void testSetTemplateLoaderAndCache() throws Exception {
Configuration cfg = new Configuration();
CacheStorageWithGetSize cacheStorage = (CacheStorageWithGetSize) cfg.getCacheStorage();
assertEquals(0, cacheStorage.getSize());
cfg.setCacheStorage(new StrongCacheStorage());
cacheStorage = (CacheStorageWithGetSize) cfg.getCacheStorage();
assertEquals(0, cacheStorage.getSize());
cfg.setClassForTemplateLoading(ConfigurationTest.class, "");
assertEquals(0, cacheStorage.getSize());
cfg.getTemplate("toCache1.ftl");
assertEquals(1, cacheStorage.getSize());
cfg.getTemplate("toCache2.ftl");
assertEquals(2, cacheStorage.getSize());
cfg.setClassForTemplateLoading(ConfigurationTest.class, "");
assertEquals(0, cacheStorage.getSize());
cfg.getTemplate("toCache1.ftl");
assertEquals(1, cacheStorage.getSize());
cfg.setTemplateLoader(cfg.getTemplateLoader());
assertEquals(1, cacheStorage.getSize());
}
use of freemarker.cache.StrongCacheStorage in project alfresco-remote-api by Alfresco.
the class RepositoryTemplateProcessor method initConfig.
/**
* Initialise FreeMarker Configuration
*/
protected void initConfig() {
Configuration config = new Configuration();
// setup template cache
config.setCacheStorage(new StrongCacheStorage());
config.setTemplateUpdateDelay(updateDelay);
// setup template loaders
List<TemplateLoader> loaders = new ArrayList<TemplateLoader>();
for (Store apiStore : searchPath.getStores()) {
TemplateLoader loader = apiStore.getTemplateLoader();
if (loader == null) {
throw new WebScriptException("Unable to retrieve template loader for Web Script store " + apiStore.getBasePath());
}
loaders.add(loader);
}
MultiTemplateLoader loader = new MultiTemplateLoader(loaders.toArray(new TemplateLoader[loaders.size()]));
config.setTemplateLoader(loader);
// use our custom object wrapper that can deal with QNameMap objects directly
config.setObjectWrapper(new QNameAwareObjectWrapper());
// rethrow any exception so we can deal with them
config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
// turn off locale sensitive lookup - to save numerous wasted calls to nodeservice.exists()
config.setLocalizedLookup(false);
// set template encoding
if (defaultEncoding != null) {
config.setDefaultEncoding(defaultEncoding);
}
// set output encoding
config.setOutputEncoding("UTF-8");
config.setIncompatibleImprovements(new Version(2, 3, 20));
config.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);
templateConfig = config;
}
use of freemarker.cache.StrongCacheStorage in project freemarker by apache.
the class ConfigurationTest method testChangingLocalizedLookupClearsCache.
public void testChangingLocalizedLookupClearsCache() throws Exception {
Configuration cfg = new Configuration();
cfg.setCacheStorage(new StrongCacheStorage());
CacheStorageWithGetSize cache = (CacheStorageWithGetSize) cfg.getCacheStorage();
cache = (CacheStorageWithGetSize) cfg.getCacheStorage();
assertEquals(0, cache.getSize());
cfg.setClassForTemplateLoading(ConfigurationTest.class, "");
assertEquals(0, cache.getSize());
cfg.getTemplate("toCache1.ftl");
assertEquals(1, cache.getSize());
cfg.setLocalizedLookup(true);
assertEquals(1, cache.getSize());
cfg.setLocalizedLookup(false);
assertEquals(0, cache.getSize());
cfg.getTemplate("toCache1.ftl");
assertEquals(1, cache.getSize());
cfg.setLocalizedLookup(false);
assertEquals(1, cache.getSize());
cfg.setLocalizedLookup(true);
assertEquals(0, cache.getSize());
}
Aggregations