Class SparseTranslationOverrideStrategy
java.lang.Object
org.broadleafcommerce.common.i18n.service.SparseTranslationOverrideStrategy
- All Implemented Interfaces:
OverridePreCacheInitializer
,TranslationOverrideStrategy
,org.springframework.core.Ordered
@Component("blSparseTranslationOverrideStrategy")
public class SparseTranslationOverrideStrategy
extends Object
implements TranslationOverrideStrategy, OverridePreCacheInitializer
A retrieval and caching strategy for translations. Primarily supports multitenant scenarios with the following characteristics:
- A very large template translation catalog
- A small number of standard site overrides
- Small or large quantity of individual standard sites
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.- Author:
- Jeff Fischer
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected TranslationDao
protected jakarta.persistence.EntityManager
protected TemplateOnlyQueryExtensionManager
static final int
protected OverridePreCacheService
protected boolean
Whether or not to restrict the template search to the catalog/site of an associated item.protected boolean
Whether or notgetLocaleBasedTemplateValue(String, String, TranslatedEntity, String, String, String, String, String)
will be utilized from this strategy.Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected String
getCacheKey
(TranslatedEntity type, String entityId, String fieldName, String localeCode) protected String
getCacheKey
(Translation translation) getLocaleBasedOverride
(String property, TranslatedEntity entityType, String entityId, String localeCode, String localeCountryCode, String basicCacheKey) Retrieve the standard site override translation, if applicablegetLocaleBasedTemplateValue
(String templateCacheKey, String property, TranslatedEntity entityType, String entityId, String localeCode, String localeCountryCode, String specificPropertyKey, String generalPropertyKey) Retrieve the template level translation, if applicableint
getOrder()
protected List<Translation>
getTemplateTranslations
(TranslatedEntity entityType, String entityId, String property, String localeCode) initializeOverride
(Object entity) Perform any initialization tasks (e.g. exercising a lazy collection) and returns a StandardCacheItem instance.boolean
isOverrideQualified
(Class<?> type) Whether or not this initializer is qualified to work on the given entity typeboolean
boolean
void
setRestrictAssociation
(boolean restrictAssociation) void
setTemplateEnabled
(boolean templateEnabled) boolean
validateTemplateProcessing
(String standardCacheKey, String templateCacheKey) Whether or not a template version should be searched for.
-
Field Details
-
PRECACHED_SPARSE_OVERRIDE_ORDER
public static final int PRECACHED_SPARSE_OVERRIDE_ORDER- See Also:
-
preCachedSparseOverrideService
-
extensionManager
-
em
protected jakarta.persistence.EntityManager em -
dao
-
templateEnabled
@Value("${precached.sparse.override.translation.template.enabled:true}") protected boolean templateEnabledWhether or notgetLocaleBasedTemplateValue(String, String, TranslatedEntity, String, String, String, String, String)
will be utilized from this strategy. If false, the fallbackThresholdCacheTranslationOverrideStrategy.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. SeeTranslationSupport.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. -
restrictAssociation
@Value("${precached.sparse.override.translation.template.search.restrict.association:false}") protected boolean restrictAssociationWhether or not to restrict the template search to the catalog/site of an associated item. For example, restrict the translation of name for a Sku to the catalog of the Sku. Or, restrict the translation of StructuredContent property to the site discriminator of the StructuredContent. This value is false by default. Change the 'precached.sparse.override.translation.template.search.restrict.association' to true to enable.
-
-
Constructor Details
-
SparseTranslationOverrideStrategy
public SparseTranslationOverrideStrategy()
-
-
Method Details
-
getLocaleBasedOverride
public LocalePair getLocaleBasedOverride(String property, TranslatedEntity entityType, String entityId, String localeCode, String localeCountryCode, String basicCacheKey) Description copied from interface:TranslationOverrideStrategy
Retrieve the standard site override translation, if applicable- Specified by:
getLocaleBasedOverride
in interfaceTranslationOverrideStrategy
- Returns:
-
getLocaleBasedTemplateValue
public LocalePair getLocaleBasedTemplateValue(String templateCacheKey, String property, TranslatedEntity entityType, String entityId, String localeCode, String localeCountryCode, String specificPropertyKey, String generalPropertyKey) Description copied from interface:TranslationOverrideStrategy
Retrieve the template level translation, if applicable- Specified by:
getLocaleBasedTemplateValue
in interfaceTranslationOverrideStrategy
- Returns:
-
isOverrideQualified
Description copied from interface:OverridePreCacheInitializer
Whether or not this initializer is qualified to work on the given entity type- Specified by:
isOverrideQualified
in interfaceOverridePreCacheInitializer
- Returns:
-
initializeOverride
Description copied from interface:OverridePreCacheInitializer
Perform any initialization tasks (e.g. exercising a lazy collection) and returns a StandardCacheItem instance.- Specified by:
initializeOverride
in interfaceOverridePreCacheInitializer
- Returns:
-
validateTemplateProcessing
Description copied from interface:TranslationOverrideStrategy
Whether or not a template version should be searched for. If false, then the system will return null for the translation, should an override not be found.- Specified by:
validateTemplateProcessing
in interfaceTranslationOverrideStrategy
- Returns:
-
getOrder
public int getOrder()- Specified by:
getOrder
in interfaceorg.springframework.core.Ordered
-
isTemplateEnabled
public boolean isTemplateEnabled() -
setTemplateEnabled
public void setTemplateEnabled(boolean templateEnabled) -
isRestrictAssociation
public boolean isRestrictAssociation() -
setRestrictAssociation
public void setRestrictAssociation(boolean restrictAssociation) -
getTemplateTranslations
protected List<Translation> getTemplateTranslations(TranslatedEntity entityType, String entityId, String property, String localeCode) -
getCacheKey
-
getCacheKey
protected String getCacheKey(TranslatedEntity type, String entityId, String fieldName, String localeCode)
-