Overview | Package | Class
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## groovy.servlet
Class TemplateCacheEntry

Simple cache entry that validates against last modified and length attributes of the specified file.

author:
  Christian Stein

Field Summary
`Map` | `cache`
`Date` | `date`
`TemplateEngine` | `engine`
`boolean` | `generateBy`
`long` | `hit`
`long` | `lastModified`
`long` | `length`
`Template` | `template`

Constructor Summary
`TemplateCacheEntry(File file, Template template)`
`TemplateCacheEntry(File file, Template template, boolean timestamp)`

Method Summary
`def` | `TemplateServlet()` Simple file name to template cache map.
`Template` | `getTemplate(File file)` Gets the template created by the underlying engine parsing the request.
`void` | `init(ServletConfig config)` Initializes the servlet from hints the container passes.
`TemplateEngine` | `initTemplateEngine(ServletConfig config)`
`void` | `service(HttpServletRequest request, HttpServletResponse response)` Services the request with a response.
`void` | `setVariables(ServletBinding binding)`
`String` | `toString()`
`boolean` | `validate(File file)` Checks the passed file attributes against those cached ones.

Constructor Detail

### TemplateCacheEntry

    public TemplateCacheEntry(File file, Template template)

### TemplateCacheEntry

    public TemplateCacheEntry(File file, Template template, boolean timestamp)

Method Detail

### TemplateServlet

    public def TemplateServlet()

  Simple file name to template cache map.

### getTemplate

    Template getTemplate(File file)

  Gets the template created by the underlying engine parsing the request.

  This method looks up a simple (weak) hash map for an existing template object that matches the source file. If the source file didn't change in length and its last modified stamp hasn't changed compared to a precompiled template object, this template is used. Otherwise, there is no or an invalid template object cache entry, a new one is created by the underlying template engine. This new instance is put to the cache for consecutive calls.

  return:
    The template that will produce the response text.
  param:
    file
  The HttpServletRequest.
  throws:
    ServletException
  If the request specified an invalid template source file

### init

    public void init(ServletConfig config)

  Initializes the servlet from hints the container passes.

  Delegates to sub-init methods and parses the following parameters:

  - `"generatedBy"` : boolean, appends "Generated by ..." to the HTML response text generated by this servlet.
  param:
    config
  Passed by the servlet container.
  throws:
    ServletException
  if this method encountered difficulties
  see:
    TemplateServlet#initTemplateEngine(ServletConfig)

### initTemplateEngine

    TemplateEngine initTemplateEngine(ServletConfig config)

### service

    public void service(HttpServletRequest request, HttpServletResponse response)

  Services the request with a response.

  First the request is parsed for the source file uri. If the specified file could not be found or can not be read an error message is sent as response.

  param:
    request
  The http request.
  param:
    response
  The http response.
  throws:
    IOException
  if an input or output error occurs while the servlet is handling the HTTP request
  throws:
    ServletException
  if the HTTP request cannot be handled

### setVariables

    void setVariables(ServletBinding binding)

### toString

    public String toString()

### validate

    public boolean validate(File file)

  Checks the passed file attributes against those cached ones.
  param:
    file
  Other file handle to compare to the cached values.
  return:
    `true` if all measured values match, else `false`