Interface CacheTemplate

  • All Known Implementing Classes:
    DefaultCacheTemplate

    public interface CacheTemplate
    Template 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
      CacheService getCacheService()
      Returns the underlying cache service used.
      Object 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 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,
                        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