Class DefaultCacheTemplate

java.lang.Object
org.craftercms.core.util.cache.impl.DefaultCacheTemplate
All Implemented Interfaces:
CacheTemplate
Direct Known Subclasses:
NonLockingCacheTemplate, NoopCacheTemplate

public class DefaultCacheTemplate extends Object implements CacheTemplate
Class description goes HERE
Author:
Alfonso Vásquez
  • Constructor Details

    • DefaultCacheTemplate

      public DefaultCacheTemplate(CacheService cacheService)
  • Method Details

    • getCacheService

      public CacheService getCacheService()
      Description copied from interface: CacheTemplate
      Returns the underlying cache service used.
      Specified by:
      getCacheService in interface CacheTemplate
    • getKey

      public Object getKey(Object... keyElements)
      Description copied from interface: CacheTemplate
      Creates a key from the specified elements
      Specified by:
      getKey in interface CacheTemplate
      Parameters:
      keyElements - the key elements
      Returns:
      the key
    • hasObject

      public boolean hasObject(Context context, Object... keyElements)
      Description copied from interface: CacheTemplate
      Returns true if the cache contains an object for the specified key elements
      Specified by:
      hasObject in interface CacheTemplate
      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: CacheTemplate
      Executes the template, using the specified callback to load the object to cache, if it's not already in the cache. Works like CacheTemplate.getObject(org.craftercms.core.service.Context, org.craftercms.core.service.CachingOptions, org.craftercms.commons.lang.Callback, Object...), but with default caching options.
      Specified by:
      getObject in interface CacheTemplate
      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

      public <T> T getObject(Context context, CachingOptions cachingOptions, org.craftercms.commons.lang.Callback<T> callback, Object... keyElements)
      Description copied from interface: CacheTemplate
      Executes the template, using the specified callback to load the object to cache, if it's not already in the cache.
      Specified by:
      getObject in interface CacheTemplate
      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
    • 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)
    • logPutFailure

      protected void logPutFailure(Context context, org.craftercms.commons.lang.Callback<?> callback, Object key, Object obj, Exception e)