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).
-
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionCaffeineBudgetManager(CaffeineConfigurers.BasicCaffeineConfigurer configurer, CaffeineProperties properties, io.micrometer.core.instrument.MeterRegistry registry, ExecutorService refreshExecutor) -
Method Summary
Modifier and TypeMethodDescriptionvoidRegisters a cache region with the manager.voidaddService(String serviceName, org.springframework.cache.caffeine.CaffeineCacheManager cacheManager, int heapBudget) Registers a service with the manager.voidapply()Calculates the memory distribution and initializes all registered caches for all registered services.intgetPhase()booleanvoidstart()voidstop()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.SmartLifecycle
isAutoStartup, stop
-
Constructor Details
-
CaffeineBudgetManager
public CaffeineBudgetManager(CaffeineConfigurers.BasicCaffeineConfigurer configurer, CaffeineProperties properties, io.micrometer.core.instrument.MeterRegistry registry, ExecutorService refreshExecutor)
-
-
Method Details
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
start
public void start()- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
getPhase
public int getPhase()- Specified by:
getPhasein interfaceorg.springframework.context.Phased- Specified by:
getPhasein interfaceorg.springframework.context.SmartLifecycle
-
addCache
Registers a cache region with the manager. Initialization is deferred untilapply()is called.- Parameters:
serviceName- the name of the service (e.g., "catalog")cacheName- the name of the cache regionttl- the time-to-live durationweightHint- 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 untilapply()is called.- Parameters:
serviceName- the name of the service (e.g., "catalog")cacheManager- the Caffeine cache managerheapBudget- 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.
-