AbstractAccessLogValve.DateFormatCache (Apache Tomcat 11.0.23 API Documentation)
Description: declaration: package: org.apache.catalina.valves, class: AbstractAccessLogValve, class: DateFormatCache

# Class AbstractAccessLogValve.DateFormatCache

java.lang.Object
org.apache.catalina.valves.AbstractAccessLogValve.DateFormatCache

Enclosing class:
  `AbstractAccessLogValve`

protected static class AbstractAccessLogValve.DateFormatCache extends Object

Cache structure for formatted timestamps based on seconds.

The cache consists of entries for a consecutive range of seconds. The length of the range is configurable. It is implemented based on a cyclic buffer. New entries shift the range.

There is one cache for the CLF format (the access log standard format) and a HashMap of caches for additional formats used by SimpleDateFormat.

Although the cache supports specifying a locale when retrieving a formatted timestamp, each format will always use the locale given when the format was first used. New locales can only be used for new formats. The CLF format will always be formatted using the locale `en_US`.

The cache is not threadsafe. It can be used without synchronization via thread local instances, or with synchronization as a global cache.

The cache can be created with a parent cache to build a cache hierarchy. Access to the parent cache is threadsafe.

This class uses a small thread local first level cache and a bigger synchronized global second level cache.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `protected class`
  `AbstractAccessLogValve.DateFormatCache.Cache`
  Cache for formatted timestamps.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final AbstractAccessLogValve.DateFormatCache.Cache`
  `cLFCache`
  The cache for CLF format.

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `DateFormatCache(int size, Locale loc, AbstractAccessLogValve.DateFormatCache parentFC)`
  Creates a new date format cache.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `getFormat(long time)`
  Gets the formatted timestamp in CLF format.
  `String`
  `getFormat(String format, Locale loc, long time)`
  Gets the formatted timestamp in the given format.

  ### Methods inherited from class Object

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

- ## Field Details

  - ### cLFCache

    protected final AbstractAccessLogValve.DateFormatCache.Cache cLFCache
    The cache for CLF format.

- ## Constructor Details

  - ### DateFormatCache

    protected DateFormatCache(int size, Locale loc, AbstractAccessLogValve.DateFormatCache parentFC)
    Creates a new date format cache.
    Parameters:
      `size` - The cache size
      `loc` - The default locale
      `parentFC` - The parent cache

- ## Method Details

  - ### getFormat

    public String getFormat(long time)
    Gets the formatted timestamp in CLF format.
    Parameters:
      `time` - The time in milliseconds
    Returns:
      The formatted timestamp

  - ### getFormat

    public String getFormat(String format, Locale loc, long time)
    Gets the formatted timestamp in the given format.
    Parameters:
      `format` - The format string
      `loc` - The locale
      `time` - The time in milliseconds
    Returns:
      The formatted timestamp