Class AbstractAsynchronouslyRefreshedCache<T>

java.lang.Object
org.alfresco.util.cache.AbstractAsynchronouslyRefreshedCache<T>
All Implemented Interfaces:
Callable<Void>, AsynchronouslyRefreshedCache<T>, RefreshableCache<T>, RefreshableCacheListener, TransactionListener, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean

public abstract class AbstractAsynchronouslyRefreshedCache<T> extends Object implements AsynchronouslyRefreshedCache<T>, RefreshableCacheListener, Callable<Void>, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, TransactionListener
The base implementation for an asynchronously refreshed cache. Currently supports one value or a cache per key (such as tenant.) Implementors just need to provide buildCache(String key/tennnantId)
Since:
4.1.3
Author:
Andy, mrogers MER 17/04/2014 Refactored to core and generalised tennancy
  • Field Details

  • Constructor Details

    • AbstractAsynchronouslyRefreshedCache

      public AbstractAsynchronouslyRefreshedCache()
  • Method Details

    • register

      public void register(RefreshableCacheListener listener)
      Description copied from interface: RefreshableCache
      Register to be informed when the cache is updated in the background. Note: it is up to the implementation to provide any transactional wrapping. Transactional wrapping is not required to invalidate a shared cache entry directly via a transactional cache
      Specified by:
      register in interface RefreshableCache<T>
      Parameters:
      listener - RefreshableCacheListener
    • setThreadPoolExecutor

      public void setThreadPoolExecutor(ThreadPoolExecutor threadPoolExecutor)
      Parameters:
      threadPoolExecutor - the threadPoolExecutor to set
    • setRegistry

      public void setRegistry(AsynchronouslyRefreshedCacheRegistry registry)
      Parameters:
      registry - the registry to set
    • init

      public void init()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • get

      public T get(String key)
      Description copied from interface: RefreshableCache
      Get the cache. If there is no cache value this call will block. If the underlying cache is being refreshed, the old cache value will be returned until the refresh is complete.
      Specified by:
      get in interface RefreshableCache<T>
      Returns:
      T
    • forceInChangesForThisUncommittedTransaction

      public void forceInChangesForThisUncommittedTransaction(String key)
      Use the current thread to build and put a new version of the cache entry before returning.
      Parameters:
      key - the cache key
    • waitForBuild

      protected void waitForBuild(org.alfresco.util.cache.AbstractAsynchronouslyRefreshedCache.Refresh refresh)
    • refresh

      public void refresh(String key)
      Description copied from interface: RefreshableCache
      Refresh the cache asynchronously.
      Specified by:
      refresh in interface RefreshableCache<T>
    • onRefreshableCacheEvent

      public void onRefreshableCacheEvent(RefreshableCacheEvent refreshableCacheEvent)
      Description copied from interface: RefreshableCacheListener
      Callback made when a cache refresh occurs
      Specified by:
      onRefreshableCacheEvent in interface RefreshableCacheListener
      Parameters:
      refreshableCacheEvent - the cache event
    • isUpToDate

      public boolean isUpToDate(String key)
      Description copied from interface: AsynchronouslyRefreshedCache
      Determine if the cache is up to date
      Specified by:
      isUpToDate in interface AsynchronouslyRefreshedCache<T>
      Parameters:
      key - tennant id
      Returns:
      true if the cache is not currently refreshing itself
    • call

      public Void call()
      Specified by:
      call in interface Callable<T>
    • setBeanName

      public void setBeanName(String name)
      Specified by:
      setBeanName in interface org.springframework.beans.factory.BeanNameAware
    • getCacheId

      public String getCacheId()
      Description copied from interface: AsynchronouslyRefreshedCache
      Get the cache id
      Specified by:
      getCacheId in interface AsynchronouslyRefreshedCache<T>
      Specified by:
      getCacheId in interface RefreshableCacheListener
      Returns:
      the cache ID
    • buildCache

      protected abstract T buildCache(String key)
      Build the cache entry for the specific key. This method is called in a thread-safe manner i.e. it is only ever called by a single thread.
      Parameters:
      key -
      Returns:
      new Cache instance
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception
    • broadcastEvent

      public void broadcastEvent(RefreshableCacheEvent event)
    • beforeCommit

      public void beforeCommit(boolean readOnly)
      Description copied from interface: TransactionListener
      Called before a transaction is committed.

      All transaction resources are still available.

      Specified by:
      beforeCommit in interface TransactionListener
      Parameters:
      readOnly - true if the transaction is read-only
    • beforeCompletion

      public void beforeCompletion()
      Description copied from interface: TransactionListener
      Invoked before transaction commit/rollback. Will be called after TransactionListener.beforeCommit(boolean) even if TransactionListener.beforeCommit(boolean) failed.

      All transaction resources are still available.

      Specified by:
      beforeCompletion in interface TransactionListener
    • afterCommit

      public void afterCommit()
      Description copied from interface: TransactionListener
      Invoked after transaction commit.

      Any exceptions generated here will only be logged and will have no effect on the state of the transaction.

      Although all transaction resources are still available, this method should be used only for cleaning up resources after a commit has occured.

      Specified by:
      afterCommit in interface TransactionListener
    • afterRollback

      public void afterRollback()
      Description copied from interface: TransactionListener
      Invoked after transaction rollback.

      Any exceptions generated here will only be logged and will have no effect on the state of the transaction.

      Although all transaction resources are still available, this method should be used only for cleaning up resources after a rollback has occured.

      Specified by:
      afterRollback in interface TransactionListener