Class XanthicSpringCacheManager

java.lang.Object
io.github.xanthic.cache.spring.XanthicSpringCacheManager
All Implemented Interfaces:
org.springframework.cache.CacheManager

public class XanthicSpringCacheManager extends Object implements org.springframework.cache.CacheManager
CacheManager implementation that lazily builds XanthicCache instances for each getCache(java.lang.String) request. Also supports a 'static' mode where the set of cache names is pre-defined through cacheNames in the constructor, with no dynamic creation of further cache regions at runtime. The configuration of the underlying cache can be fine-tuned through the CacheApiSpec, passed into this CacheManager in the constructor.
  • Constructor Details

    • XanthicSpringCacheManager

      public XanthicSpringCacheManager(Consumer<io.github.xanthic.cache.core.CacheApiSpec<Object,Object>> spec)
      XanthicSpringCacheManager will manage all xanthic cache instances for spring.
      Parameters:
      spec - the default CacheApiSpec used to create a new cache instances
    • XanthicSpringCacheManager

      public XanthicSpringCacheManager(Consumer<io.github.xanthic.cache.core.CacheApiSpec<Object,Object>> spec, @Nullable Collection<String> cacheNames)
      XanthicSpringCacheManager will manage all xanthic cache instances for spring.
      Parameters:
      spec - the default CacheApiSpec used to create a new cache instances
      cacheNames - If not null, the number of caches and their names will be fixed, with no creation of further cache keys at runtime.
  • Method Details

    • getCache

      @Nullable public org.springframework.cache.Cache getCache(@NotNull @NotNull String name)
      Specified by:
      getCache in interface org.springframework.cache.CacheManager
    • getCacheNames

      @NotNull public @NotNull Collection<String> getCacheNames()
      Specified by:
      getCacheNames in interface org.springframework.cache.CacheManager
    • registerCache

      public void registerCache(String name, Consumer<io.github.xanthic.cache.core.CacheApiSpec<Object,Object>> spec)
      Register a custom xanthic cache by customizing the CacheApiSpec.
      Parameters:
      name - the name of the cache
      spec - configuration for the specified cache
    • getCustomCacheNames

      public Set<String> getCustomCacheNames()