public class SparseOverridePreCacheServiceImpl extends Object implements org.springframework.context.SmartLifecycle, org.broadleafcommerce.common.cache.OverridePreCacheService
OverridePreCacheService. This implementation will review WorkflowCloneLibrary
instances to find any and all production, standard site overrides that are qualified. Then it will review and cache the entities
referenced in those override declarations. This serves as a fast cache for site-level overrides.
The cache has several grooming strategies.
groomCacheBySiteOverride(String, Long, boolean) will add or remove a cache member based on a WorkflowCloneLibrary changegroomCacheByTargetEntity(String, Serializable) will update the value of an existing member in the cacherefreshCache() can be called explicitly to destroy and rebuild the cache. This is done in a thread safe and read efficient way.SparseSiteOverrideSystemEventConsumer and SparseOverrideEntityInvalidationSystemEventConsumer
for the specific event listeners.
This cache is disabled by default. Set the 'precached.sparse.override.cache.enable' property to true to enable.
This implementation employs an Ehcache cache to hold the values. The cache is configured to be eternal and to roll over to disk with a
default of 5000 elements retained in memory. You can control the size of the in-memory portion of the cache by setting
the 'precached.sparse.override.max.elements.inmemory' property.
This implementation also uses a scheduled task to call the refreshCache() method on an interval. This serves as
a fail-safe should normal cache grooming be ineffectual. The default interval is 3600000 ms (1 hour) and can be controlled
via the 'precached.sparse.override.refresh.interval.millis' property.
By default, even if enabled, the cache will be inactive until one or more SparseOverridePreCacheQualifiedEntityPattern beans
are registered. This class allows for flexible include/exclude configuration of entity types based on regular
expressions. You generally configure your patterns in your application context or Configuration class. Here is an
example in xml:
<bean id="myPatterns" class="org.springframework.beans.factory.config.ListFactoryBean">
<property name="sourceList">
<list>
<bean class="com.broadleafcommerce.tenant.service.cache.SparseOverridePreCacheQualifiedEntityPattern">
<property name="include" value="true"/>
<property name="regex" value=".*(Translation|TranslationImpl)"/>
</bean>
</list>
</property>
</bean>
<bean class="org.broadleafcommerce.common.extensibility.context.merge.LateStageMergeBeanPostProcessor">
<property name="collectionRef" value="myPatterns" />
<property name="targetRef" value="blPreCachedSparseOverrideQualifiedEntityPatterns" />
</bean>
Note, this cache is generally used in conjuction with one or more override strategies. See these strategies for more
information:
isActiveIsolatedSiteForType(Long, String).| Modifier and Type | Field and Description |
|---|---|
protected int |
cloneCount |
protected javax.cache.Cache |
currentCache |
protected javax.persistence.EntityManager |
em |
protected boolean |
enabled |
protected boolean |
groomingEnabled |
protected List<org.broadleafcommerce.common.cache.OverridePreCacheInitializer> |
handlers |
protected boolean |
isStarted |
protected org.broadleafcommerce.common.extensibility.cache.JCacheUtil |
jcacheUtil |
protected ReadWriteLock |
lock |
protected int |
maxElementsInMemory |
protected List<SparseOverridePreCacheQualifiedEntityPattern> |
qualifiedEntityPatterns |
protected long |
refreshInterval |
protected Map<String,Set<Long>> |
sitesWithIsolatedValuesByType |
protected Timer |
timer |
protected org.broadleafcommerce.common.util.StreamingTransactionCapableUtil |
transUtil |
protected ConcurrentHashMap<String,Boolean> |
typeStatus |
| Constructor and Description |
|---|
SparseOverridePreCacheServiceImpl() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
applyToCache(Class<?> type,
List<Long> sitesWithIsolatedValues,
Map<String,Set<Long>> isolatedSiteCache) |
protected void |
applyToCache(Class<?> type,
List results,
javax.cache.Cache cache,
boolean isRemove) |
List<org.broadleafcommerce.common.extension.StandardCacheItem> |
findElements(String... cacheKeys) |
javax.cache.Cache |
getCurrentCache() |
protected List |
getFullCacheResults(String qualifiedType,
Class<?> type,
javax.persistence.EntityManager em) |
List<org.broadleafcommerce.common.cache.OverridePreCacheInitializer> |
getHandlers() |
int |
getPhase() |
List<SparseOverridePreCacheQualifiedEntityPattern> |
getQualifiedEntityPatterns() |
protected List<String> |
getQualifiedTypes(javax.persistence.EntityManager em) |
protected List<Long> |
getStandardSitesContainingIsolatedValues(Class<?> type,
javax.persistence.EntityManager em) |
protected List<String> |
getStaticQualifiedTypes(javax.persistence.EntityManager em) |
protected Class<?> |
getType(String entityType) |
void |
groomCacheBySiteOverride(String entityType,
Long cloneId,
boolean isRemove) |
void |
groomCacheByTargetEntity(String entityType,
Serializable id) |
boolean |
isActiveForType(String type) |
boolean |
isActiveIsolatedSiteForType(Long siteId,
String entityType) |
boolean |
isAutoStartup() |
boolean |
isEnabled() |
boolean |
isGroomingEnabled() |
boolean |
isRunning() |
protected void |
populateCache(javax.persistence.EntityManager em,
List<String> qualifiedTypes,
javax.cache.Cache clone) |
protected void |
populateCache(javax.persistence.EntityManager em,
List<String> staticQualifiedTypes,
Map<String,Set<Long>> isolatedSiteCache) |
void |
refreshCache() |
void |
setCurrentCache(javax.cache.Cache currentCache) |
void |
setEnabled(boolean enabled) |
void |
setGroomingEnabled(boolean groomingEnabled) |
void |
setHandlers(List<org.broadleafcommerce.common.cache.OverridePreCacheInitializer> handlers) |
void |
setQualifiedEntityPatterns(List<SparseOverridePreCacheQualifiedEntityPattern> qualifiedEntityPatterns) |
void |
start() |
void |
stop() |
void |
stop(Runnable callback) |
protected void |
swap(javax.cache.Cache clone,
Map<String,Set<Long>> isolatedSitesClone) |
@Value(value="${precached.sparse.override.cache.enable:false}")
protected boolean enabled
@Value(value="${precached.sparse.override.max.elements.inmemory:5000}")
protected int maxElementsInMemory
@Value(value="${precached.sparse.override.refresh.interval.millis:3600000}")
protected long refreshInterval
@Value(value="${precached.sparse.override.incremental.cache.grooming.enabled:true}")
protected boolean groomingEnabled
protected List<SparseOverridePreCacheQualifiedEntityPattern> qualifiedEntityPatterns
protected org.broadleafcommerce.common.util.StreamingTransactionCapableUtil transUtil
protected List<org.broadleafcommerce.common.cache.OverridePreCacheInitializer> handlers
protected javax.persistence.EntityManager em
protected org.broadleafcommerce.common.extensibility.cache.JCacheUtil jcacheUtil
protected javax.cache.Cache currentCache
protected int cloneCount
protected ReadWriteLock lock
protected ConcurrentHashMap<String,Boolean> typeStatus
protected boolean isStarted
protected Timer timer
public boolean isAutoStartup()
isAutoStartup in interface org.springframework.context.SmartLifecyclepublic void stop(Runnable callback)
stop in interface org.springframework.context.SmartLifecyclepublic void start()
start in interface org.springframework.context.Lifecyclepublic void stop()
stop in interface org.springframework.context.Lifecyclepublic boolean isRunning()
isRunning in interface org.springframework.context.Lifecyclepublic int getPhase()
getPhase in interface org.springframework.context.PhasedgetPhase in interface org.springframework.context.SmartLifecyclepublic List<org.broadleafcommerce.common.extension.StandardCacheItem> findElements(String... cacheKeys)
findElements in interface org.broadleafcommerce.common.cache.OverridePreCacheServicepublic boolean isActiveIsolatedSiteForType(Long siteId, String entityType)
isActiveIsolatedSiteForType in interface org.broadleafcommerce.common.cache.OverridePreCacheServicepublic boolean isActiveForType(String type)
isActiveForType in interface org.broadleafcommerce.common.cache.OverridePreCacheServicepublic void groomCacheBySiteOverride(String entityType, Long cloneId, boolean isRemove)
groomCacheBySiteOverride in interface org.broadleafcommerce.common.cache.OverridePreCacheServicepublic void refreshCache()
refreshCache in interface org.broadleafcommerce.common.cache.OverridePreCacheServicepublic void groomCacheByTargetEntity(String entityType, Serializable id)
groomCacheByTargetEntity in interface org.broadleafcommerce.common.cache.OverridePreCacheServicepublic boolean isEnabled()
public void setEnabled(boolean enabled)
public javax.cache.Cache getCurrentCache()
public void setCurrentCache(javax.cache.Cache currentCache)
protected void applyToCache(Class<?> type, List results, javax.cache.Cache cache, boolean isRemove)
protected void applyToCache(Class<?> type, List<Long> sitesWithIsolatedValues, Map<String,Set<Long>> isolatedSiteCache)
protected void populateCache(javax.persistence.EntityManager em,
List<String> qualifiedTypes,
javax.cache.Cache clone)
protected void populateCache(javax.persistence.EntityManager em,
List<String> staticQualifiedTypes,
Map<String,Set<Long>> isolatedSiteCache)
protected List getFullCacheResults(String qualifiedType, Class<?> type, javax.persistence.EntityManager em)
protected List<Long> getStandardSitesContainingIsolatedValues(Class<?> type, javax.persistence.EntityManager em)
protected List<String> getStaticQualifiedTypes(javax.persistence.EntityManager em)
public List<SparseOverridePreCacheQualifiedEntityPattern> getQualifiedEntityPatterns()
public void setQualifiedEntityPatterns(List<SparseOverridePreCacheQualifiedEntityPattern> qualifiedEntityPatterns)
public List<org.broadleafcommerce.common.cache.OverridePreCacheInitializer> getHandlers()
public void setHandlers(List<org.broadleafcommerce.common.cache.OverridePreCacheInitializer> handlers)
public boolean isGroomingEnabled()
public void setGroomingEnabled(boolean groomingEnabled)
Copyright © 2020. All rights reserved.