Class 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.
    • 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)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • executorService

        private final java.util.concurrent.ExecutorService executorService
      • 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 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> 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 key
        value - 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)