public class

LazyLoadingCache

extends Object
java.lang.Object
   ↳ com.atlassian.jira.cache.LazyLoadingCache<D>

Class Overview

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.

Summary

Nested Classes
interface LazyLoadingCache.CacheLoader<D>  
Public Constructors
LazyLoadingCache(CacheLoader<D> cacheLoader)
Public Methods
D getData()
Gets the cache data object.
synchronized 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.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public LazyLoadingCache (CacheLoader<D> cacheLoader)

Public Methods

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.

public synchronized 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

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