use of freemarker.cache.CacheStorageWithGetSize 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.CacheStorageWithGetSize in project freemarker by apache.
the class ConfigurationTest method testTemplateLookupStrategyDefaultAndSet.
public void testTemplateLookupStrategyDefaultAndSet() throws IOException {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
assertSame(TemplateLookupStrategy.DEFAULT_2_3_0, cfg.getTemplateLookupStrategy());
cfg.setClassForTemplateLoading(ConfigurationTest.class, "");
assertSame(TemplateLookupStrategy.DEFAULT_2_3_0, cfg.getTemplateLookupStrategy());
CacheStorageWithGetSize cache = (CacheStorageWithGetSize) cfg.getCacheStorage();
cfg.setClassForTemplateLoading(ConfigurationTest.class, "");
assertEquals(0, cache.getSize());
cfg.getTemplate("toCache1.ftl");
assertEquals(1, cache.getSize());
cfg.setTemplateLookupStrategy(TemplateLookupStrategy.DEFAULT_2_3_0);
assertEquals(1, cache.getSize());
final TemplateLookupStrategy myStrategy = new TemplateLookupStrategy() {
@Override
public TemplateLookupResult lookup(TemplateLookupContext ctx) throws IOException {
return ctx.lookupWithAcquisitionStrategy(ctx.getTemplateName());
}
};
cfg.setTemplateLookupStrategy(myStrategy);
assertEquals(0, cache.getSize());
assertSame(myStrategy, cfg.getTemplateLookupStrategy());
cfg.getTemplate("toCache1.ftl");
assertEquals(1, cache.getSize());
cfg.setTemplateLookupStrategy(myStrategy);
assertEquals(1, cache.getSize());
cfg.setTemplateLookupStrategy(TemplateLookupStrategy.DEFAULT_2_3_0);
assertEquals(0, cache.getSize());
}
use of freemarker.cache.CacheStorageWithGetSize 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.CacheStorageWithGetSize 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