Class CacheConfiguration

  • Direct Known Subclasses:
    DiscoveryClientCacheConfiguration

    public class CacheConfiguration
    extends java.lang.Object

    A base configuration class for configuring caches.

    Since:
    1.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.nio.charset.Charset charset  
      static boolean DEFAULT_RECORD_STATS
      The default record stats value.
      static boolean DEFAULT_TESTMODE
      The default test mode value.
      static java.lang.String PREFIX
      The prefix for cache configuration.
    • Constructor Summary

      Constructors 
      Constructor Description
      CacheConfiguration​(java.lang.String cacheName, io.micronaut.runtime.ApplicationConfiguration applicationConfiguration)
      Creates a new cache with the given name.
    • Field Detail

      • PREFIX

        public static final java.lang.String PREFIX
        The prefix for cache configuration.
        See Also:
        Constant Field Values
      • DEFAULT_RECORD_STATS

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

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

        protected java.nio.charset.Charset charset
    • Constructor Detail

      • CacheConfiguration

        public CacheConfiguration​(@Parameter
                                  java.lang.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 Detail

      • getCacheName

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

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

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

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

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

        public java.util.Optional<java.time.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 java.nio.charset.Charset getCharset()
        Returns:
        The charset used to serialize and deserialize values
      • setInitialCapacity

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

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

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

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

        public void setExpireAfterAccess​(java.time.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​(java.nio.charset.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