Cache (Apache Tomcat 11.0.24 API Documentation)
Description: declaration: package: org.apache.catalina.webresources, class: Cache

# Class Cache

java.lang.Object
org.apache.catalina.webresources.Cache

public class Cache extends Object
Cache for web resources managed by a StandardRoot.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected static final StringManager`
  `sm`
  String manager for internationalized messages.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Cache(StandardRoot root)`
  Constructs a cache for the given root.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `backgroundProcess()`
  Performs background cache maintenance, evicting expired entries.
  `void`
  `clear()`
  Clears all entries from the cache.
  `WebResourceRoot.CacheStrategy`
  `getCacheStrategy()`
  Returns the cache strategy.
  `long`
  `getHitCount()`
  Returns the total number of cache hits.
  `long`
  `getLookupCount()`
  Returns the total number of cache lookups.
  `long`
  `getMaxSize()`
  Returns the maximum cache size in kilobytes.
  `int`
  `getObjectMaxSize()`
  Returns the maximum size of a single cached object in kilobytes.
  `int`
  `getObjectMaxSizeBytes()`
  Returns the maximum size of a single cached object in bytes.
  `protected WebResource`
  `getResource(String path, boolean useClassLoaderResources)`
  Retrieves a single resource from the cache.
  `protected WebResource[]`
  `getResources(String path, boolean useClassLoaderResources)`
  Retrieves multiple resources from the cache.
  `long`
  `getSize()`
  Returns the current cache size in kilobytes.
  `long`
  `getTtl()`
  Returns the time-to-live for cached entries.
  `void`
  `setCacheStrategy(WebResourceRoot.CacheStrategy cacheStrategy)`
  Sets the cache strategy.
  `void`
  `setMaxSize(long maxSize)`
  Sets the maximum cache size in kilobytes.
  `void`
  `setObjectMaxSize(int objectMaxSize)`
  Sets the maximum size of a single cached object in kilobytes.
  `void`
  `setTtl(long ttl)`
  Sets the time-to-live for cached entries.

  ### Methods inherited from class Object

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

- ## Field Details

  - ### sm

    protected static final StringManager sm
    String manager for internationalized messages.

- ## Constructor Details

  - ### Cache

    public Cache(StandardRoot root)
    Constructs a cache for the given root.
    Parameters:
      `root` - the standard root

- ## Method Details

  - ### getResource

    protected WebResource getResource(String path, boolean useClassLoaderResources)
    Retrieves a single resource from the cache.
    Parameters:
      `path` - resource path
      `useClassLoaderResources` - whether to use class loader resources
    Returns:
      the web resource

  - ### getResources

    protected WebResource[] getResources(String path, boolean useClassLoaderResources)
    Retrieves multiple resources from the cache.
    Parameters:
      `path` - resource path
      `useClassLoaderResources` - whether to use class loader resources
    Returns:
      the web resources

  - ### backgroundProcess

    protected void backgroundProcess()
    Performs background cache maintenance, evicting expired entries.

  - ### getCacheStrategy

    public WebResourceRoot.CacheStrategy getCacheStrategy()
    Returns the cache strategy.
    Returns:
      the cache strategy

  - ### setCacheStrategy

    public void setCacheStrategy(WebResourceRoot.CacheStrategy cacheStrategy)
    Sets the cache strategy.
    Parameters:
      `cacheStrategy` - the cache strategy

  - ### getTtl

    public long getTtl()
    Returns the time-to-live for cached entries.
    Returns:
      the TTL in milliseconds

  - ### setTtl

    public void setTtl(long ttl)
    Sets the time-to-live for cached entries.
    Parameters:
      `ttl` - the TTL in milliseconds

  - ### getMaxSize

    public long getMaxSize()
    Returns the maximum cache size in kilobytes.
    Returns:
      the maximum size in KB

  - ### setMaxSize

    public void setMaxSize(long maxSize)
    Sets the maximum cache size in kilobytes.
    Parameters:
      `maxSize` - the maximum size in KB

  - ### getLookupCount

    public long getLookupCount()
    Returns the total number of cache lookups.
    Returns:
      the lookup count

  - ### getHitCount

    public long getHitCount()
    Returns the total number of cache hits.
    Returns:
      the hit count

  - ### setObjectMaxSize

    public void setObjectMaxSize(int objectMaxSize)
    Sets the maximum size of a single cached object in kilobytes.
    Parameters:
      `objectMaxSize` - the maximum object size in KB

  - ### getObjectMaxSize

    public int getObjectMaxSize()
    Returns the maximum size of a single cached object in kilobytes.
    Returns:
      the maximum object size in KB

  - ### getObjectMaxSizeBytes

    public int getObjectMaxSizeBytes()
    Returns the maximum size of a single cached object in bytes.
    Returns:
      the maximum object size in bytes

  - ### clear

    public void clear()
    Clears all entries from the cache.

  - ### getSize

    public long getSize()
    Returns the current cache size in kilobytes.
    Returns:
      the current size in KB