Class DefaultSynchronizationCacheService
- java.lang.Object
-
- de.hybris.platform.cmsfacades.synchronization.cache.impl.DefaultSynchronizationCacheService
-
- All Implemented Interfaces:
SynchronizationCacheService
public class DefaultSynchronizationCacheService extends java.lang.Object implements SynchronizationCacheService
Default implementation ofSynchronizationCacheService.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringSYNCHRONIZATION_ITEM_CACHE
-
Constructor Summary
Constructors Constructor Description DefaultSynchronizationCacheService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.StringgetCacheKey(ItemModel... items)Generates the cache based on the list of items.protected <T> java.lang.ObjectgetFromCacheOrRetrieve(java.util.function.Supplier<T> supplier, java.lang.String cacheKey)Retrieves the value from cache if it exists in the cache.<T> TgetOrSetItemCache(java.util.function.Supplier<T> supplier, java.lang.String cacheKey)Retrieves the item from the cache.<T> java.util.List<T>getOrSetItemListCache(java.util.function.Supplier<java.util.List<T>> supplier, java.lang.String cacheKey)Retrieves the list of items from the cache.<T> java.util.List<T>getOrSetItemListCache(java.util.function.Supplier<java.util.List<T>> supplier, java.lang.String cachePrefix, ItemModel... itemsForKeys)Retrieves the list of items from the cache.SessionCachedContextProvidergetSessionCachedContextProvider()voidinitCache()Initialize the cache, it creates cache objects in current session.voidsetSessionCachedContextProvider(SessionCachedContextProvider sessionCachedContextProvider)
-
-
-
Field Detail
-
SYNCHRONIZATION_ITEM_CACHE
public static final java.lang.String SYNCHRONIZATION_ITEM_CACHE
- See Also:
- Constant Field Values
-
-
Method Detail
-
initCache
public void initCache()
Description copied from interface:SynchronizationCacheServiceInitialize the cache, it creates cache objects in current session.- Specified by:
initCachein interfaceSynchronizationCacheService
-
getOrSetItemCache
public <T> T getOrSetItemCache(java.util.function.Supplier<T> supplier, java.lang.String cacheKey)Description copied from interface:SynchronizationCacheServiceRetrieves the item from the cache. If cache does not contain an item the supplier is called to populate the cache and return the value.- Specified by:
getOrSetItemCachein interfaceSynchronizationCacheService- Parameters:
supplier- the supplier to execute if item does not exist in cache.cacheKey- the cache key- Returns:
- the item
-
getOrSetItemListCache
public <T> java.util.List<T> getOrSetItemListCache(java.util.function.Supplier<java.util.List<T>> supplier, java.lang.String cacheKey)Description copied from interface:SynchronizationCacheServiceRetrieves the list of items from the cache. If cache does not contain any items the supplier is called to populate the cache and return the value.- Specified by:
getOrSetItemListCachein interfaceSynchronizationCacheService- Type Parameters:
T- the type T represents any java type.- Parameters:
supplier- the supplier to execute if items does not exist in cache.cacheKey- the cache key- Returns:
- the list of items.
-
getOrSetItemListCache
public <T> java.util.List<T> getOrSetItemListCache(java.util.function.Supplier<java.util.List<T>> supplier, java.lang.String cachePrefix, ItemModel... itemsForKeys)Description copied from interface:SynchronizationCacheServiceRetrieves the list of items from the cache. If cache does not contain any items the supplier is called to populate the cache and return the value.- Specified by:
getOrSetItemListCachein interfaceSynchronizationCacheService- Type Parameters:
T- the type T represents any java type.- Parameters:
supplier- the supplier to execute if items does not exist in cache.cachePrefix- the cache prefix (is concatenated with the cache key generated based on itemsForKeys)itemsForKeys- the list of items that are used to generate a cache key.- Returns:
- the list of items.
-
getFromCacheOrRetrieve
protected <T> java.lang.Object getFromCacheOrRetrieve(java.util.function.Supplier<T> supplier, java.lang.String cacheKey)Retrieves the value from cache if it exists in the cache. If not exist, the value is provided by the supplier and put in the cache.- Type Parameters:
T- the type T can represent any java type (collection included)- Parameters:
supplier- the supplier of the valuecacheKey- the cache key- Returns:
- the value.
-
getCacheKey
protected java.lang.String getCacheKey(ItemModel... items)
Generates the cache based on the list of items.- Parameters:
items- the list of items.- Returns:
- the cache key.
-
getSessionCachedContextProvider
public SessionCachedContextProvider getSessionCachedContextProvider()
-
setSessionCachedContextProvider
public void setSessionCachedContextProvider(SessionCachedContextProvider sessionCachedContextProvider)
-
-