Class EhcacheBudgetManager
java.lang.Object
com.broadleafcommerce.common.extension.cache.ehcache.EhcacheBudgetManager
- All Implemented Interfaces:
org.springframework.context.Lifecycle,org.springframework.context.Phased,org.springframework.context.SmartLifecycle
public class EhcacheBudgetManager
extends Object
implements org.springframework.context.SmartLifecycle
Manages memory budgeting and initialization for Ehcache 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
ConstructorsConstructorDescriptionEhcacheBudgetManager(EhcacheConfigurers.BasicEhcacheConfigurer configurer, EhcacheProperties properties, io.micrometer.core.instrument.MeterRegistry registry, ExecutorService refreshExecutor) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCache(String serviceName, String cacheName, Duration ttl, double weightHint, int estimatedSizeHint) Registers a cache region with the manager.voidaddService(String serviceName, org.springframework.cache.jcache.JCacheCacheManager cacheManager, int heapBudget, int offHeapBudget) 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
-
EhcacheBudgetManager
public EhcacheBudgetManager(EhcacheConfigurers.BasicEhcacheConfigurer configurer, EhcacheProperties 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
public void addCache(String serviceName, String cacheName, Duration ttl, double weightHint, int estimatedSizeHint) 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)estimatedSizeHint- the estimated average size of a single cache entry in bytes
-
addService
public void addService(String serviceName, org.springframework.cache.jcache.JCacheCacheManager cacheManager, int heapBudget, int offHeapBudget) Registers a service with the manager. Initialization is deferred untilapply()is called.- Parameters:
serviceName- the name of the service (e.g., "catalog")cacheManager- the JCache cache managerheapBudget- the total heap budget in MB for the serviceoffHeapBudget- the total off-heap budget in MB for the service
-
apply
public void apply()Calculates the memory distribution and initializes all registered caches for all registered services.
-