com.twitter.common.base
Class CachingSupplier<T>

java.lang.Object
  extended by com.twitter.common.base.CachingSupplier<T>
Type Parameters:
T - Supplied value type.
All Implemented Interfaces:
Supplier<T>, ExceptionalSupplier<T,RuntimeException>

public class CachingSupplier<T>
extends Object
implements Supplier<T>

A supplier that caches responses from an underling supplier, expiring the cached value after a fixed expiration time.


Constructor Summary
CachingSupplier(Supplier<T> wrapped, Amount<Long,Time> expiration)
          Creates a new caching supplier.
 
Method Summary
 T get()
          Supplies an item, possibly throwing E in the process of obtaining the item.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachingSupplier

public CachingSupplier(Supplier<T> wrapped,
                       Amount<Long,Time> expiration)
Creates a new caching supplier.

Parameters:
wrapped - The supplier to delegate fetches to.
expiration - The maximum amount of time that a response from supplier will be cached for. The expiration must be positive.
Method Detail

get

public T get()
Description copied from interface: ExceptionalSupplier
Supplies an item, possibly throwing E in the process of obtaining the item.

Specified by:
get in interface Supplier<T>
Specified by:
get in interface ExceptionalSupplier<T,RuntimeException>
Returns:
the result of the computation