Class CaffeineBudgetManager

java.lang.Object
com.broadleafcommerce.common.extension.cache.caffeine.CaffeineBudgetManager
All Implemented Interfaces:
org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle

public class CaffeineBudgetManager extends Object implements org.springframework.context.SmartLifecycle
Manages memory budgeting and initialization for Caffeine regions across services. This manager allows for adaptive rebalancing of cache weights if additional caches are added (e.g., via extensions).
  • Constructor Details

  • Method Details

    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface org.springframework.context.Lifecycle
    • start

      public void start()
      Specified by:
      start in interface org.springframework.context.Lifecycle
    • stop

      public void stop()
      Specified by:
      stop in interface org.springframework.context.Lifecycle
    • getPhase

      public int getPhase()
      Specified by:
      getPhase in interface org.springframework.context.Phased
      Specified by:
      getPhase in interface org.springframework.context.SmartLifecycle
    • addCache

      public void addCache(String serviceName, String cacheName, Duration ttl, double weightHint)
      Registers a cache region with the manager. Initialization is deferred until apply() is called.
      Parameters:
      serviceName - the name of the service (e.g., "catalog")
      cacheName - the name of the cache region
      ttl - the time-to-live duration
      weightHint - the relative weight of this cache region (0.0 to 1.0)
    • addService

      public void addService(String serviceName, org.springframework.cache.caffeine.CaffeineCacheManager cacheManager, int heapBudget)
      Registers a service with the manager. Initialization is deferred until apply() is called.
      Parameters:
      serviceName - the name of the service (e.g., "catalog")
      cacheManager - the Caffeine cache manager
      heapBudget - the total heap budget in MB for the service
    • apply

      public void apply()
      Calculates the memory distribution and initializes all registered caches for all registered services.