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 Type
    Method
    Description
    Returns the underlying cache service used.
    getKey(Object... keyElements)
    Creates a key from the specified elements
    <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.
    <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
    hasObject(Context context, Object... keyElements)
    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

      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 like getObject(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 cache
      keyElements - 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 cache
      keyElements - the key elements, used to create the final cache key
      Returns:
      the cached object