@Component(value="blSparseTranslationOverrideStrategy") public class SparseTranslationOverrideStrategy extends Object implements TranslationOverrideStrategy, OverridePreCacheInitializer
ThresholdCacheTranslationOverrideStrategy
,
this strategy opts for completely caching overrides and minimizing template queries. The highest template query optimization
is achieved in conjunction with the 'precached.sparse.override.template.search.restrict.catalog' property set to true (false by
default). See com.broadleafcommerce.tenant.service.extension.MultiTenantTemplateOnlyQueryExtensionHandler for more information,
since this setting assumes the translated entity is in the same catalog as the Translation
instance, which may
not be true for all installations.
Hybrid configurations are also possible for small to medium size template translation catalogs where the threshold
count bounding queries are not a concern and complete (or partial) caching of the template catalog can be achieved. However,
such a strategy may provide little to no benefit over the out-of-the-box ThresholdCacheTranslationOverrideStrategy
.
See the templateEnabled
property for more information.
This strategy also works best when there are few standard sites with isolated values (i.e. the value was created in the standard
site and was not inherited from a profile or catalog). This is because the strategy can utilize an optimized template
query that is portable across sites if it doesn't have to take into account the standard site. The strategy uses
OverridePreCacheService.isActiveIsolatedSiteForType(Long, String)
to figure out this state.
This strategy is disabled by default. Please see the javadoc for com.broadleafcommerce.tenant.service.cache.SparseOverridePreCacheServiceImpl (MultiTenant only)
for more information on how to enable this strategy via configuration of that service.ThresholdCacheTranslationOverrideStrategy
Modifier and Type | Field and Description |
---|---|
protected TranslationDao |
dao |
protected javax.persistence.EntityManager |
em |
protected TemplateOnlyQueryExtensionManager |
extensionManager |
static int |
PRECACHED_SPARSE_OVERRIDE_ORDER |
protected OverridePreCacheService |
preCachedSparseOverrideService |
protected boolean |
restrictAssociation
Whether or not to restrict the template search to the catalog/site of an associated item.
|
protected boolean |
templateEnabled
Whether or not
getLocaleBasedTemplateValue(String, String, TranslatedEntity, String, String, String, String, String)
will be utilized from this strategy. |
Constructor and Description |
---|
SparseTranslationOverrideStrategy() |
Modifier and Type | Method and Description |
---|---|
protected String |
getCacheKey(TranslatedEntity type,
String entityId,
String fieldName,
String localeCode) |
protected String |
getCacheKey(Translation translation) |
LocalePair |
getLocaleBasedOverride(String property,
TranslatedEntity entityType,
String entityId,
String localeCode,
String localeCountryCode,
String basicCacheKey)
Retrieve the standard site override translation, if applicable
|
LocalePair |
getLocaleBasedTemplateValue(String templateCacheKey,
String property,
TranslatedEntity entityType,
String entityId,
String localeCode,
String localeCountryCode,
String specificPropertyKey,
String generalPropertyKey)
Retrieve the template level translation, if applicable
|
int |
getOrder() |
protected List<Translation> |
getTemplateTranslations(TranslatedEntity entityType,
String entityId,
String property,
String localeCode) |
StandardCacheItem |
initializeOverride(Object entity)
Perform any initialization tasks (e.g.
|
boolean |
isOverrideQualified(Class<?> type)
Whether or not this initializer is qualified to work on the given entity type
|
boolean |
isRestrictAssociation() |
boolean |
isTemplateEnabled() |
void |
setRestrictAssociation(boolean restrictAssociation) |
void |
setTemplateEnabled(boolean templateEnabled) |
boolean |
validateTemplateProcessing(String standardCacheKey,
String templateCacheKey)
Whether or not a template version should be searched for.
|
public static final int PRECACHED_SPARSE_OVERRIDE_ORDER
protected OverridePreCacheService preCachedSparseOverrideService
protected TemplateOnlyQueryExtensionManager extensionManager
protected javax.persistence.EntityManager em
protected TranslationDao dao
@Value(value="${precached.sparse.override.translation.template.enabled:true}") protected boolean templateEnabled
getLocaleBasedTemplateValue(String, String, TranslatedEntity, String, String, String, String, String)
will be utilized from this strategy. If false, the fallback
ThresholdCacheTranslationOverrideStrategy.getLocaleBasedTemplateValue(String, String, TranslatedEntity, String, String, String, String, String)
will be used instead.
If the 'template' repository (MT concept) is large, this value should be left true. However, if the 'template' repository
is relatively small, you may want to consider setting this to false in order to leverage the possibility of complete
caching in the default strategy. See TranslationSupport.getThresholdForFullCache()
for more info on this
option.
The default value is true. Set the 'precached.sparse.override.translation.template.enabled' property to change the value.
This value is meaningless if the current standard site is found to contain active isolated values for translations.
Review the documentation in com.broadleafcommerce.tenant.service.cache.SparseOverridePreCacheServiceImpl for more information.@Value(value="${precached.sparse.override.translation.template.search.restrict.association:false}") protected boolean restrictAssociation
public LocalePair getLocaleBasedOverride(String property, TranslatedEntity entityType, String entityId, String localeCode, String localeCountryCode, String basicCacheKey)
TranslationOverrideStrategy
getLocaleBasedOverride
in interface TranslationOverrideStrategy
public LocalePair getLocaleBasedTemplateValue(String templateCacheKey, String property, TranslatedEntity entityType, String entityId, String localeCode, String localeCountryCode, String specificPropertyKey, String generalPropertyKey)
TranslationOverrideStrategy
getLocaleBasedTemplateValue
in interface TranslationOverrideStrategy
public boolean isOverrideQualified(Class<?> type)
OverridePreCacheInitializer
isOverrideQualified
in interface OverridePreCacheInitializer
public StandardCacheItem initializeOverride(Object entity)
OverridePreCacheInitializer
initializeOverride
in interface OverridePreCacheInitializer
public boolean validateTemplateProcessing(String standardCacheKey, String templateCacheKey)
TranslationOverrideStrategy
validateTemplateProcessing
in interface TranslationOverrideStrategy
public int getOrder()
getOrder
in interface org.springframework.core.Ordered
public boolean isTemplateEnabled()
public void setTemplateEnabled(boolean templateEnabled)
public boolean isRestrictAssociation()
public void setRestrictAssociation(boolean restrictAssociation)
protected List<Translation> getTemplateTranslations(TranslatedEntity entityType, String entityId, String property, String localeCode)
protected String getCacheKey(Translation translation)
protected String getCacheKey(TranslatedEntity type, String entityId, String fieldName, String localeCode)
Copyright © 2022. All rights reserved.