Class DefaultCacheTemplate
java.lang.Object
org.craftercms.core.util.cache.impl.DefaultCacheTemplate
- All Implemented Interfaces:
CacheTemplate
- Direct Known Subclasses:
NonLockingCacheTemplate,NoopCacheTemplate
Class description goes HERE
- Author:
- Alfonso Vásquez
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected <T> Tprotected <T> TdoPut(Context context, CachingOptions cachingOptions, org.craftercms.commons.lang.Callback<T> callback, Object key, T obj) protected <T> CacheLoadergetCacheLoader(org.craftercms.commons.lang.Callback<T> callback, long refreshFrequency) Returns the underlying cache service used.Creates a key from the specified elements<T> TExecutes the template, using the specified callback to load the object to cache, if it's not already in the cache.<T> TgetObject(Context context, CachingOptions cachingOptions, org.craftercms.commons.lang.Callback<T> callback, Object... keyElements) Executes the template, using the specified callback to load the object to cache, if it's not already in the cache.booleanReturns true if the cache contains an object for the specified key elementsprotected <T> TloadAndPutInCache(Context context, CachingOptions cachingOptions, org.craftercms.commons.lang.Callback<T> callback, Object key) protected voidlogGetFailure(Context context, org.craftercms.commons.lang.Callback<?> callback, Object key, Exception e) protected voidlogPutFailure(Context context, org.craftercms.commons.lang.Callback<?> callback, Object key, Object obj, Exception e)
-
Constructor Details
-
DefaultCacheTemplate
-
-
Method Details
-
getCacheService
Description copied from interface:CacheTemplateReturns the underlying cache service used.- Specified by:
getCacheServicein interfaceCacheTemplate
-
getKey
Description copied from interface:CacheTemplateCreates a key from the specified elements- Specified by:
getKeyin interfaceCacheTemplate- Parameters:
keyElements- the key elements- Returns:
- the key
-
hasObject
Description copied from interface:CacheTemplateReturns true if the cache contains an object for the specified key elements- Specified by:
hasObjectin interfaceCacheTemplate- Parameters:
context- the context (needed by the cache service)keyElements- the key elements, used to create the final cache key- Returns:
- true if the cache contains an object for the specified key elements
-
getObject
public <T> T getObject(Context context, org.craftercms.commons.lang.Callback<T> callback, Object... keyElements) Description copied from interface:CacheTemplateExecutes the template, using the specified callback to load the object to cache, if it's not already in the cache. Works likeCacheTemplate.getObject(org.craftercms.core.service.Context, org.craftercms.core.service.CachingOptions, org.craftercms.commons.lang.Callback, Object...), but with default caching options.- Specified by:
getObjectin interfaceCacheTemplate- Parameters:
context- the context (needed by the cache service)callback- the callback to use in case the object is not in the cachekeyElements- the key elements, used to create the final cache key- Returns:
- the cached object
-
getObject
public <T> T getObject(Context context, CachingOptions cachingOptions, org.craftercms.commons.lang.Callback<T> callback, Object... keyElements) Description copied from interface:CacheTemplateExecutes the template, using the specified callback to load the object to cache, if it's not already in the cache.- Specified by:
getObjectin interfaceCacheTemplate- Parameters:
context- the context (needed by the cache service)cachingOptions- the options used for caching.callback- the callback to use in case the object is not in the cachekeyElements- the key elements, used to create the final cache key- Returns:
- the cached object
-
doGet
-
loadAndPutInCache
protected <T> T loadAndPutInCache(Context context, CachingOptions cachingOptions, org.craftercms.commons.lang.Callback<T> callback, Object key) -
doPut
protected <T> T doPut(Context context, CachingOptions cachingOptions, org.craftercms.commons.lang.Callback<T> callback, Object key, T obj) -
getCacheLoader
protected <T> CacheLoader getCacheLoader(org.craftercms.commons.lang.Callback<T> callback, long refreshFrequency) -
logGetFailure
-
logPutFailure
-