Package groovy.text.markup

# Class MarkupTemplateEngine.CachingTemplateResolver

java.lang.Object
groovy.text.markup.MarkupTemplateEngine.DefaultTemplateResolver
groovy.text.markup.MarkupTemplateEngine.CachingTemplateResolver

All Implemented Interfaces:
  `TemplateResolver`

Enclosing class:
  MarkupTemplateEngine

public static class MarkupTemplateEngine.CachingTemplateResolver extends MarkupTemplateEngine.DefaultTemplateResolver
A template resolver which avoids calling `ClassLoader.getResource(String)` if a template path already has been queried before. This improves performance if caching is enabled in the configuration.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final Map<String,URL>`
  `cache`
  Backing cache keyed by logical template path.
  `protected boolean`
  `useCache`
  Indicates whether this resolver should consult and populate its cache.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CachingTemplateResolver()`
  Creates a new caching template resolver using a concurrent hash map as the backing cache.
  `CachingTemplateResolver(Map<String,URL> cache)`
  Creates a new caching template resolver.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `configure(ClassLoader templateClassLoader, TemplateConfiguration configuration)`
  This method is called once the template engine is initialized, providing the resolver with the template engine configuration and its template class loader.
  `URL`
  `resolveTemplate(String templatePath)`
  Resolvers must implement this method in order to resolve a template, given a template path.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### cache

    protected final Map<String,URL> cache
    Backing cache keyed by logical template path.

  - ### useCache

    protected boolean useCache
    Indicates whether this resolver should consult and populate its cache.

- ## Constructor Details

  - ### CachingTemplateResolver

    public CachingTemplateResolver(Map<String,URL> cache)
    Creates a new caching template resolver. The cache implementation being used depends on the use of the template engine. If multiple templates can be rendered in parallel, it must be using a thread-safe cache.
    Parameters:
      `cache` - the backing cache

  - ### CachingTemplateResolver

    public CachingTemplateResolver()
    Creates a new caching template resolver using a concurrent hash map as the backing cache.

- ## Method Details

  - ### configure

    public void configure(ClassLoader templateClassLoader, TemplateConfiguration configuration)
    This method is called once the template engine is initialized, providing the resolver with the template engine configuration and its template class loader.
    Specified by:
      `configure` in interface `TemplateResolver`
    Overrides:
      `configure` in class `MarkupTemplateEngine.DefaultTemplateResolver`
    Parameters:
      `templateClassLoader` - the classloader where templates will be searched for
      `configuration` - the configuration of the template engine

  - ### resolveTemplate

    public URL resolveTemplate(String templatePath) throws IOException
    Resolvers must implement this method in order to resolve a template, given a template path. They must return a valid URL or an IOException.
    Specified by:
      `resolveTemplate` in interface `TemplateResolver`
    Overrides:
      `resolveTemplate` in class `MarkupTemplateEngine.DefaultTemplateResolver`
    Parameters:
      `templatePath` - path to the template
    Returns:
      the template URL, that will be used to load the template
    Throws:
      `IOException`