本文整理汇总了Java中freemarker.template.Configuration.setCacheStorage方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.setCacheStorage方法的具体用法?Java Configuration.setCacheStorage怎么用?Java Configuration.setCacheStorage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类freemarker.template.Configuration
的用法示例。
在下文中一共展示了Configuration.setCacheStorage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStringConfig
import freemarker.template.Configuration; //导入方法依赖的package包/类
/**
* FreeMarker configuration for loading the specified template directly from a String
*
* @param path Pseudo Path to the template
* @param template Template content
*
* @return FreeMarker configuration
*/
protected Configuration getStringConfig(String path, String template)
{
Configuration config = new Configuration();
// setup template cache
config.setCacheStorage(new MruCacheStorage(2, 0));
// use our custom loader to load a template directly from a String
StringTemplateLoader stringTemplateLoader = new StringTemplateLoader();
stringTemplateLoader.putTemplate(path, template);
config.setTemplateLoader(stringTemplateLoader);
// use our custom object wrapper that can deal with QNameMap objects directly
config.setObjectWrapper(qnameObjectWrapper);
// rethrow any exception so we can deal with them
config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
// set default template encoding
if (defaultEncoding != null)
{
config.setDefaultEncoding(defaultEncoding);
}
config.setIncompatibleImprovements(new Version(2, 3, 20));
config.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);
return config;
}
示例2: createConfig
import freemarker.template.Configuration; //导入方法依赖的package包/类
private Configuration createConfig(){
Configuration config = new Configuration(new Version(2, 3, 23));
config.setDefaultEncoding("UTF-8");
config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
config.setCacheStorage(NullCacheStorage.INSTANCE);
return config;
}
示例3: main
import freemarker.template.Configuration; //导入方法依赖的package包/类
public static void main( String[] args )
{
CommandLineOptions options = new CommandLineOptions();
new JCommander(options, args);
logger.finest("Options.debug = " + options.debug);
logger.finest("Options.servicePort = " + options.servicePort);
port(options.servicePort);
FreeMarkerEngine freeMarkerEngine = new FreeMarkerEngine();
Configuration freeMarkerConfiguration = new Configuration();
freeMarkerConfiguration.setTemplateLoader(new ClassTemplateLoader(App.class, "/"));
if (options.debug) {
freeMarkerConfiguration.setCacheStorage(new NullCacheStorage());
WebpackThread.run();
}
freeMarkerEngine.setConfiguration(freeMarkerConfiguration);
if (options.debug) {
String projectDir = System.getProperty("user.dir");
String staticDir = "/src/main/frontend/public";
staticFiles.externalLocation(projectDir + staticDir);
} else {
staticFileLocation("/public");
}
get("/", (request, response) -> {
if (shouldReturnHtml(request)) {
response.status(200);
response.type("text/html");
Map<String, Object> attributes = new HashMap<>();
return freeMarkerEngine.render(new ModelAndView(attributes, "index.ftl"));
} else {
response.status(200);
response.type("application/json");
return dataToJson(null);
}
});
get("/alive", (request, response) -> "ok");
}