net.spy.memcached.util
Class CacheLoader

java.lang.Object
  extended by net.spy.memcached.compat.SpyObject
      extended by net.spy.memcached.util.CacheLoader

public class CacheLoader
extends SpyObject

CacheLoader provides efficient mechanisms for storing lots of data.


Nested Class Summary
static interface CacheLoader.StorageListener
          If you are interested in the results of your data load, this interface will receive them.
 
Constructor Summary
CacheLoader(MemcachedClientIF c)
          Simple CacheLoader constructor that doesn't provide any feedback and caches forever.
CacheLoader(MemcachedClientIF c, ExecutorService es, CacheLoader.StorageListener sl, int exp)
          Get a CacheLoader with all the options.
 
Method Summary
<T> Future<?>
loadData(Iterator<Map.Entry<String,T>> i)
          Load data from the given iterator.
<T> Future<?>
loadData(Map<String,T> map)
          Load data from the given map.
<T> Future<Boolean>
push(String k, T value)
          Push a value into the cache.
 
Methods inherited from class net.spy.memcached.compat.SpyObject
getLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheLoader

public CacheLoader(MemcachedClientIF c)
Simple CacheLoader constructor that doesn't provide any feedback and caches forever.

Parameters:
c - a client

CacheLoader

public CacheLoader(MemcachedClientIF c,
                   ExecutorService es,
                   CacheLoader.StorageListener sl,
                   int exp)
Get a CacheLoader with all the options.

Parameters:
c - a client
es - an ExecutorService (e.g. thread pool) to dispatch results (may be null, in which case no listener may be provided)
sl - a storage listener (may be null)
exp - expiration to use while loading
Method Detail

loadData

public <T> Future<?> loadData(Iterator<Map.Entry<String,T>> i)
Load data from the given iterator.

Type Parameters:
T - type of data being loaded
Parameters:
i - the iterator of data to load

loadData

public <T> Future<?> loadData(Map<String,T> map)
Load data from the given map.

Type Parameters:
T - type of data being loaded
Parameters:
map - the map of keys to values that needs to be loaded

push

public <T> Future<Boolean> push(String k,
                                T value)
Push a value into the cache. This is a wrapper around set that throttles and retries on full queues.

Type Parameters:
T - the type being stored
Parameters:
k - the key
value - the value
Returns:
the future representing the stored data