Class ProtobufRedisLoadingCache<K extends com.google.protobuf.Message,V extends com.google.protobuf.Message>
- java.lang.Object
-
- org.curioswitch.common.server.framework.redis.ProtobufRedisLoadingCache<K,V>
-
public class ProtobufRedisLoadingCache<K extends com.google.protobuf.Message,V extends com.google.protobuf.Message> extends java.lang.Object
AAsyncLoadingCache
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ProtobufRedisLoadingCache.Factory
AProtobufRedisLoadingCache.Factory
for creatingProtobufRedisLoadingCache
.
-
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 givenkey
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 givenkey
, computing the value fromloader
if it is not present in cache.com.google.common.util.concurrent.ListenableFuture<V>
getIfPresent(K key)
Returns the value for the givenkey
if it is present in cache, otherwise returnsnull
.com.google.common.util.concurrent.ListenableFuture<V>
put(K key, V value)
Sets the givenvalue
for the givenkey
in cache.
-
-
-
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 givenkey
, computing the value fromloader
if it is not present in cache.
-
getIfPresent
public com.google.common.util.concurrent.ListenableFuture<V> getIfPresent(K key)
Returns the value for the givenkey
if it is present in cache, otherwise returnsnull
.
-
put
public com.google.common.util.concurrent.ListenableFuture<V> put(K key, V value)
Sets the givenvalue
for the givenkey
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, useget(Message, Function)
.
-
deleteFromRedis
public com.google.common.util.concurrent.ListenableFuture<java.lang.Boolean> deleteFromRedis(K key)
Deletes the givenkey
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 withtrue
if the key was present and deleted orfalse
if the key was not present at all.
-
-