Class CaffeineScheme

All Implemented Interfaces:
BackingMapManagerBuilder, BuilderCustomization<CaffeineCache>, MapBuilder, NamedCacheBuilder, ServiceBuilder, CachingScheme, ObservableCachingScheme, Scheme, ServiceScheme

public class CaffeineScheme extends AbstractLocalCachingScheme<CaffeineCache>
The CaffeineScheme class is responsible for building a fully configured instance of a CaffeineCache. Note that a CaffeineCache may be used as a stand-alone cache or as part of a backing map.

This class will automatically inject the following types and named values into realized classes that have been annotated with @Injectable.

  1. BackingMapManagerContext (optionally named "manager-context")
  2. ConfigurableCacheFactory
  3. Cache Name (as a String.class named "cache-name")
  4. Context ClassLoader (optionally named "class-loader")
  5. ResourceRegistry
  6. CacheConfig
  7. together with any other resource, named or otherwise, available in the ResourceRegistry provided by the ConfigurableCacheFactory.
Since:
22.06
Author:
Aleks Seovic 2022.05.12
See Also:
  • Constructor Details

    • CaffeineScheme

      public CaffeineScheme()
  • Method Details

    • realizeMap

      public CaffeineCache realizeMap(ParameterResolver resolver, MapBuilder.Dependencies dependencies)
      Description copied from class: AbstractCachingScheme
      Realize a Map based on the state of the MapBuilder, resolvable parameters and provided MapBuilder.Dependencies.
      Specified by:
      realizeMap in interface MapBuilder
      Overrides:
      realizeMap in class AbstractCachingScheme
      Parameters:
      resolver - the ParameterResolver
      dependencies - the MapBuilder.Dependencies for realizing the Map
      Returns:
      a Map
    • getExpiryDelay

      public Seconds getExpiryDelay(ParameterResolver resolver)
      Return the amount of time since the last update that entries are kept by the cache before being expired. Entries that have expired are not accessible and are evicted the next time a client accesses the cache. Any attempt to read an expired entry results in a reloading of the entry from the CacheStore.
      Parameters:
      resolver - the ParameterResolver
      Returns:
      the expiry delay
    • setExpiryDelay

      @Injectable public void setExpiryDelay(Expression<Seconds> expr)
      Set the expiry delay.
      Parameters:
      expr - the expiry delay expression
    • getHighUnits

      public Units getHighUnits(ParameterResolver resolver)
      Return the limit of cache size. Contains the maximum number of units that can be placed n the cache before pruning occurs. An entry is the unit of measurement, unless it is overridden by an alternate unit-calculator. When this limit is exceeded, the cache begins the pruning process, evicting entries according to the eviction policy. Legal values are positive integers or zero. Zero implies no limit.
      Parameters:
      resolver - the ParameterResolver
      Returns:
      the high units
    • setHighUnits

      @Injectable public void setHighUnits(Expression<Units> expr)
      Set the high units.
      Parameters:
      expr - the high units expression
    • getUnitCalculatorBuilder

      public UnitCalculatorBuilder getUnitCalculatorBuilder()
      Return the UnitCalculatorBuilder used to build a UnitCalculator.
      Returns:
      the unit calculator
    • setUnitCalculatorBuilder

      @Injectable("unit-calculator") public void setUnitCalculatorBuilder(UnitCalculatorBuilder builder)
      Set the UnitCalculatorBuilder.
      Parameters:
      builder - the UnitCalculatorBuilder
    • getUnitFactor

      public int getUnitFactor(ParameterResolver resolver)
      Return the unit-factor element specifies the factor by which the units, low-units and high-units properties are adjusted. Using a BINARY unit calculator, for example, the factor of 1048576 could be used to count megabytes instead of bytes.
      Parameters:
      resolver - the ParameterResolver
      Returns:
      the unit factor
    • setUnitFactor

      @Injectable public void setUnitFactor(Expression<Integer> expr)
      Set the unit factor.
      Parameters:
      expr - the unit factor expression
    • validate

      protected void validate(ParameterResolver resolver)
      Validate the properties.
      Overrides:
      validate in class AbstractCachingScheme
      Parameters:
      resolver - the ParameterResolver needed to resolve expressions