com.atlassian.jira.cache
Class LazyLoadingCache<D>

java.lang.Object
  extended by com.atlassian.jira.cache.LazyLoadingCache<D>

public class LazyLoadingCache<D>
extends Object

This class allows us to set up a cache that is lazy-loaded in a thread-safe way.

The type D is the type of the cache Data. It should normally be an immutable data object.

Since:
v4.0

Nested Class Summary
static interface LazyLoadingCache.CacheLoader<D>
           
 
Constructor Summary
LazyLoadingCache(LazyLoadingCache.CacheLoader<D> cacheLoader)
           
 
Method Summary
 D getData()
          Gets the cache data object.
 void reload()
          This method will load the latest cache data, and then replace the existing cache data.
 void reset()
          This method will throw away any existing cache data, and leave the LazyLoadingCache uninitialised.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LazyLoadingCache

public LazyLoadingCache(LazyLoadingCache.CacheLoader<D> cacheLoader)
Method Detail

getData

public D getData()
Gets the cache data object.

Calling this method may cause the cache data to be loaded, if it has not been loaded yet.

Returns:
the cache data object.

reload

public void reload()
This method will load the latest cache data, and then replace the existing cache data.

Note that it leaves the old cache data intact while the load is occuring in order to allow readers to continue to work without blocking.

This method is synchronized in order to stop a possible race condition that could publish stale data.

See Also:
reset()

reset

public void reset()
This method will throw away any existing cache data, and leave the LazyLoadingCache uninitialised. This means that the cache will need to be loaded on the next call to getData(), and readers will be blocked until the cache is reloaded.

See Also:
reload()


Copyright © 2002-2012 Atlassian. All Rights Reserved.