Class DefaultCacheTemplate
- java.lang.Object
-
- org.craftercms.core.util.cache.impl.DefaultCacheTemplate
-
- All Implemented Interfaces:
CacheTemplate
public class DefaultCacheTemplate extends Object implements CacheTemplate
Class description goes HERE- Author:
- Alfonso Vásquez
-
-
Constructor Summary
Constructors Constructor Description DefaultCacheTemplate()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <T> TdoGet(Context context, org.craftercms.commons.lang.Callback<T> callback, Object key)protected <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)CacheServicegetCacheService()Returns the underlying cache service used.ObjectgetKey(Object... keyElements)Creates a key from the specified elements<T> TgetObject(Context context, 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.<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.booleanhasObject(Context context, Object... keyElements)Returns 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)voidsetCacheService(CacheService cacheService)
-
-
-
Method Detail
-
getCacheService
public CacheService getCacheService()
Description copied from interface:CacheTemplateReturns the underlying cache service used.- Specified by:
getCacheServicein interfaceCacheTemplate
-
setCacheService
public void setCacheService(CacheService cacheService)
-
getKey
public Object getKey(Object... keyElements)
Description copied from interface:CacheTemplateCreates a key from the specified elements- Specified by:
getKeyin interfaceCacheTemplate- Parameters:
keyElements- the key elements- Returns:
- the key
-
hasObject
public boolean hasObject(Context context, Object... keyElements)
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
protected <T> T doGet(Context context, org.craftercms.commons.lang.Callback<T> callback, Object key)
-
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
protected void logGetFailure(Context context, org.craftercms.commons.lang.Callback<?> callback, Object key, Exception e)
-
-