com.twitter.common.util.caching
Class CachingMethodProxy<T>

java.lang.Object
  extended by com.twitter.common.util.caching.CachingMethodProxy<T>

public class CachingMethodProxy<T>
extends Object

A proxy class that handles caching of return values for method calls to a wrapped object. Example usage: Foo uncached = new Foo(); CachingMethodProxy methodProxy = CachingMethodProxy.proxyFor(uncached, Foo.class); Foo foo = methodProxy.getCachingProxy(); methodProxy.cache(foo.doBar(), lruCache1) .cache(foo.doBaz(), lruCache2) .prepare();


Method Summary
<K,V> CachingMethodProxy<T>
cache(V value, Cache<K,V> cache, Function<Object[],K> keyBuilder)
           
<K,V> CachingMethodProxy<T>
cache(V value, Cache<K,V> cache, Function<Object[],K> keyBuilder, Predicate<V> valueFilter)
           
<V> CachingMethodProxy<T>
cache(V value, Cache<List,V> cache)
           
<V> CachingMethodProxy<T>
cache(V value, Cache<List,V> cache, Predicate<V> valueFilter)
           
 T getCachingProxy()
           
 void prepare()
          Instructs the proxy that cache setup is complete, and the proxy instance should begin caching and delegating uncached calls.
static
<T> CachingMethodProxy<T>
proxyFor(T uncached, Class<T> type)
          Creates a new builder for the given type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

proxyFor

public static <T> CachingMethodProxy<T> proxyFor(T uncached,
                                                 Class<T> type)
Creates a new builder for the given type.

Type Parameters:
T - Type parameter to the proxied class.
Parameters:
uncached - The uncached object that should be insulated by caching.
type - The interface that a proxy should be created for.
Returns:
A new builder.

getCachingProxy

public T getCachingProxy()

prepare

public void prepare()
Instructs the proxy that cache setup is complete, and the proxy instance should begin caching and delegating uncached calls. After this is called, any subsequent calls to any of the cache setup methods will result in an IllegalStateException.


cache

public <V> CachingMethodProxy<T> cache(V value,
                                       Cache<List,V> cache)

cache

public <V> CachingMethodProxy<T> cache(V value,
                                       Cache<List,V> cache,
                                       Predicate<V> valueFilter)

cache

public <K,V> CachingMethodProxy<T> cache(V value,
                                         Cache<K,V> cache,
                                         Function<Object[],K> keyBuilder)

cache

public <K,V> CachingMethodProxy<T> cache(V value,
                                         Cache<K,V> cache,
                                         Function<Object[],K> keyBuilder,
                                         Predicate<V> valueFilter)