Package org.craftercms.core.util.cache
Interface CacheTemplate
-
- All Known Implementing Classes:
DefaultCacheTemplate
public interface CacheTemplateTemplate patten that allows easy usage of the cache service.- Author:
- Alfonso Vásquez
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description 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 elements
-
-
-
Method Detail
-
getCacheService
CacheService getCacheService()
Returns the underlying cache service used.
-
getKey
Object getKey(Object... keyElements)
Creates a key from the specified elements- Parameters:
keyElements- the key elements- Returns:
- the key
-
hasObject
boolean hasObject(Context context, Object... keyElements)
Returns true if the cache contains an object for the specified key elements- 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
<T> T getObject(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. Works likegetObject(org.craftercms.core.service.Context, org.craftercms.core.service.CachingOptions, org.craftercms.commons.lang.Callback, Object...), but with default caching options.- 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
<T> T getObject(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.- 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
-
-