本文整理匯總了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");
}