Class CacheConfiguration

java.lang.Object
io.micronaut.cache.CacheConfiguration
Direct Known Subclasses:
CaffeineCacheConfiguration, DiscoveryClientCacheConfiguration

public class CacheConfiguration extends Object

A base configuration class for configuring caches.

Since:
1.0
Author:
Graeme Rocher
  • Field Details

    • PREFIX

      public static final String PREFIX
      The prefix for cache configuration.
      See Also:
    • DEFAULT_RECORD_STATS

      public static final boolean DEFAULT_RECORD_STATS
      The default record stats value.
      See Also:
    • DEFAULT_TESTMODE

      public static final boolean DEFAULT_TESTMODE
      The default test mode value.
      See Also:
    • charset

      protected Charset charset
  • Constructor Details

    • CacheConfiguration

      public CacheConfiguration(@Parameter String cacheName, io.micronaut.runtime.ApplicationConfiguration applicationConfiguration)
      Creates a new cache with the given name.
      Parameters:
      cacheName - Name or key of the cache
      applicationConfiguration - The common application configuration
  • Method Details

    • getCacheName

      public String getCacheName()
      Returns:
      The name of the cache
    • getInitialCapacity

      public OptionalInt getInitialCapacity()
      Returns:
      The initial capacity of the cache
    • getMaximumSize

      public OptionalLong getMaximumSize()
      Returns:
      The maximum size of the cache
    • getMaximumWeight

      public OptionalLong getMaximumWeight()
      Returns:
      The maximum weight of cache entries
    • getExpireAfterWrite

      public Optional<Duration> getExpireAfterWrite()
      Returns:
      The expiry to use after the value is written
    • getExpireAfterAccess

      public Optional<Duration> getExpireAfterAccess()
      Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed after the entry's creation, the most recent replacement of its value, or its last read.
      Returns:
      The Duration
    • isRecordStats

      public boolean isRecordStats()
      Some caches support recording statistics. For example to record hit and miss ratio's fine tune the cache characteristics.
      Returns:
      True if record stats is enabled
    • getCharset

      public Charset getCharset()
      Returns:
      The charset used to serialize and deserialize values
    • setInitialCapacity

      public void setInitialCapacity(Integer initialCapacity)
      Parameters:
      initialCapacity - The initial cache capacity.
    • setMaximumSize

      public void setMaximumSize(Long maximumSize)
      Parameters:
      maximumSize - Specifies the maximum number of entries the cache may contain
    • setMaximumWeight

      public void setMaximumWeight(Long maximumWeight)
      Parameters:
      maximumWeight - Specifies the maximum weight of entries
    • setExpireAfterWrite

      public void setExpireAfterWrite(Duration expireAfterWrite)
      Parameters:
      expireAfterWrite - The cache expiration duration after writing into it.
    • setExpireAfterAccess

      public void setExpireAfterAccess(Duration expireAfterAccess)
      Parameters:
      expireAfterAccess - The cache expiration duration after accessing it
    • setRecordStats

      public void setRecordStats(boolean recordStats)
      Set whether record stats is enabled. Default value (false).
      Parameters:
      recordStats - True if record status is enabled
    • setCharset

      public void setCharset(Charset charset)
      Parameters:
      charset - The charset used to serialize and deserialize values
    • isTestMode

      public boolean isTestMode()
      Some caches have a test mode. For example to to enable the eager execution of cleanup operations making it easier to test.
      Returns:
      True if it test mode is enabled
    • setTestMode

      public void setTestMode(boolean testMode)
      Set whether test mode is enabled. Default value (false).
      Parameters:
      testMode - True if test mode is eanbled