freemarker.cache.MruCacheStorage Java Examples

The following examples show how to use freemarker.cache.MruCacheStorage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TemplateEngine.java    From mangooio with Apache License 2.0 6 votes vote down vote up
public TemplateEngine() {
    this.configuration.setClassForTemplateLoading(this.getClass(), Default.TEMPLATES_FOLDER.toString());
    this.configuration.setDefaultEncoding(StandardCharsets.UTF_8.name());
    this.configuration.setOutputEncoding(StandardCharsets.UTF_8.name());
    this.configuration.setLocalizedLookup(false);
    this.configuration.setNumberFormat(Default.NUMBER_FORMAT.toString());
    this.configuration.setAPIBuiltinEnabled(true);
    this.configuration.setObjectWrapper(new Java8ObjectWrapper(VERSION));
    this.configuration.setOutputFormat(HTMLOutputFormat.INSTANCE);
    this.configuration.setRecognizeStandardFileExtensions(false);

    if (Application.inDevMode()) {
        this.configuration.setTemplateUpdateDelayMilliseconds(ONE_SECOND_MS);
    } else {
        this.configuration.setTemplateUpdateDelayMilliseconds(Integer.MAX_VALUE);
        this.configuration.setCacheStorage(new MruCacheStorage(STRONG_SIZE_LIMIT, Integer.MAX_VALUE));
    }
}
 
Example #2
Source File: FreemarkerResultHandler.java    From oxygen with Apache License 2.0 5 votes vote down vote up
FreemarkerResolver() {
  cfg = new Configuration(Configuration.getVersion());
  cfg.setDefaultEncoding(StandardCharsets.UTF_8.name());
  cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
  cfg.setClassForTemplateLoading(Bootstrap.class,
      WebConfigKeys.VIEW_PREFIX_FREEMARKER.getValue());
  cfg.setNumberFormat(Strings.OCTOTHORP);
  if (WebConfigKeys.VIEW_CACHE.castValue(boolean.class)) {
    cfg.setCacheStorage(new MruCacheStorage(20, 250));
  } else {
    cfg.unsetCacheStorage();
  }
}
 
Example #3
Source File: FreeMarkerProcessor.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}