Package net.spy.memcached.util
Class CacheLoader
- java.lang.Object
-
- net.spy.memcached.compat.SpyObject
-
- net.spy.memcached.util.CacheLoader
-
public class CacheLoader extends SpyObject
CacheLoader provides efficient mechanisms for storing lots of data.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
CacheLoader.StorageListener
If you are interested in the results of your data load, this interface will receive them.
-
Field Summary
Fields Modifier and Type Field Description private MemcachedClientIF
client
private java.util.concurrent.ExecutorService
executorService
private int
expiration
private CacheLoader.StorageListener
storageListener
-
Constructor Summary
Constructors Constructor Description CacheLoader(MemcachedClientIF c)
Simple CacheLoader constructor that doesn't provide any feedback and caches forever.CacheLoader(MemcachedClientIF c, java.util.concurrent.ExecutorService es, CacheLoader.StorageListener sl, int exp)
Get a CacheLoader with all the options.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> java.util.concurrent.Future<?>
loadData(java.util.Iterator<java.util.Map.Entry<java.lang.String,T>> i)
Load data from the given iterator.<T> java.util.concurrent.Future<?>
loadData(java.util.Map<java.lang.String,T> map)
Load data from the given map.<T> java.util.concurrent.Future<java.lang.Boolean>
push(java.lang.String k, T value)
Push a value into the cache.private void
watch(java.lang.String key, java.util.concurrent.Future<java.lang.Boolean> f)
-
-
-
Field Detail
-
executorService
private final java.util.concurrent.ExecutorService executorService
-
storageListener
private final CacheLoader.StorageListener storageListener
-
client
private final MemcachedClientIF client
-
expiration
private final int expiration
-
-
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, java.util.concurrent.ExecutorService es, CacheLoader.StorageListener sl, int exp)
Get a CacheLoader with all the options.- Parameters:
c
- a clientes
- 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> java.util.concurrent.Future<?> loadData(java.util.Iterator<java.util.Map.Entry<java.lang.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> java.util.concurrent.Future<?> loadData(java.util.Map<java.lang.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> java.util.concurrent.Future<java.lang.Boolean> push(java.lang.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 keyvalue
- the value- Returns:
- the future representing the stored data
-
watch
private void watch(java.lang.String key, java.util.concurrent.Future<java.lang.Boolean> f)
-
-