Package org.craftercms.core.util.cache
Interface CacheTemplate
- All Known Implementing Classes:
DefaultCacheTemplate
,NonLockingCacheTemplate
,NoopCacheTemplate
public interface CacheTemplate
Template patten that allows easy usage of the cache service.
- Author:
- Alfonso Vásquez
-
Method Summary
Modifier and TypeMethodDescriptionReturns the underlying cache service used.Creates a key from the specified elements<T> T
Executes the template, using the specified callback to load the object to cache, if it's not already in the cache.<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.boolean
Returns true if the cache contains an object for the specified key elements
-
Method Details
-
getCacheService
CacheService getCacheService()Returns the underlying cache service used. -
getKey
Creates a key from the specified elements- Parameters:
keyElements
- the key elements- Returns:
- the key
-
hasObject
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
-