Class ProtobufRedisLoadingCache<K extends com.google.protobuf.Message,​V extends com.google.protobuf.Message>


  • public class ProtobufRedisLoadingCache<K extends com.google.protobuf.Message,​V extends com.google.protobuf.Message>
    extends java.lang.Object
    A AsyncLoadingCache that is backed by a remote remoteCache cache, specialized for the common case where the key and value are protobuf for easy serialization. This class should be used even when no local caching is desired as it ensures multiple reads of the same key share the same write to remoteCache.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      com.google.common.util.concurrent.ListenableFuture<java.lang.Boolean> deleteFromRedis​(K key)
      Deletes the given key from the remote cache.
      com.google.common.util.concurrent.ListenableFuture<V> get​(K key, java.util.function.Function<K,​com.google.common.util.concurrent.ListenableFuture<V>> loader)
      Returns the value for the given key, computing the value from loader if it is not present in cache.
      com.google.common.util.concurrent.ListenableFuture<V> getIfPresent​(K key)
      Returns the value for the given key if it is present in cache, otherwise returns null.
      com.google.common.util.concurrent.ListenableFuture<V> put​(K key, V value)
      Sets the given value for the given key in cache.
      • Methods inherited from class java.lang.Object

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

      • get

        public com.google.common.util.concurrent.ListenableFuture<V> get​(K key,
                                                                         java.util.function.Function<K,​com.google.common.util.concurrent.ListenableFuture<V>> loader)
        Returns the value for the given key, computing the value from loader if it is not present in cache.
      • getIfPresent

        public com.google.common.util.concurrent.ListenableFuture<V> getIfPresent​(K key)
        Returns the value for the given key if it is present in cache, otherwise returns null.
      • put

        public com.google.common.util.concurrent.ListenableFuture<V> put​(K key,
                                                                         V value)
        Sets the given value for the given key in cache. Simultaneous writes to the same key will result in consecutive updates, so this method should only be used when this is acceptable (e.g., for storing state that might be used to resume an operation). For general cache semantics, use get(Message, Function).
      • deleteFromRedis

        public com.google.common.util.concurrent.ListenableFuture<java.lang.Boolean> deleteFromRedis​(K key)
        Deletes the given key from the remote cache. This can be used to invalidate remote caches. It is not practical to invalidate local caches across servers, so this is only useful if the local cache is disabled everywhere (i.e., localCacheSpec is null on construction).
        Returns:
        a ListenableFuture which completes with true if the key was present and deleted or false if the key was not present at all.