Interface KeyValueStore<T>
-
- Type Parameters:
T
- the type this store puts/gets
- All Known Implementing Classes:
AbstractAsyncKeyValueStore
,AbstractKeyValueStore
,AbstractPostgresKeyValueStore
,CassandraBlobStore
,InMemoryMapBlobStore
,NoOpBlobStore
,NoOpJsonStore
,PostgresBlobStore
,PostgresJsonStore
public interface KeyValueStore<T>
Abstract representation of a simple key-value store.Any synchronous calls to this API that fail exceptionally will throw a RuntimeException wrapping the original exception.
Asynchronous calls to this API that fail exceptionally will return their future completed exceptionally with the original exception.
It is up to the client to handle failures (in the form of unchecked exceptions) resulting from calls to this interface. This is particularly important in the case of asynchronous calls as the backing implementation may be overwhelmed depending on the rate in which case the user must implement their own retry logic to handle the futures that have completed exceptionally (in any case where it is not safe to ignore them).
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
delete(java.lang.String key, java.lang.String context)
java.util.concurrent.CompletableFuture<java.lang.Void>
deleteAsync(java.lang.String key, java.lang.String context)
java.util.Map<java.lang.String,T>
enumerateContext(java.lang.String context)
java.util.concurrent.CompletableFuture<java.util.Map<java.lang.String,T>>
enumerateContextAsync(java.lang.String context)
java.util.Optional<T>
get(java.lang.String key, java.lang.String context)
java.util.concurrent.CompletableFuture<java.util.Optional<T>>
getAsync(java.lang.String key, java.lang.String context)
java.util.Optional<java.util.Optional<T>>
getIfStale(java.lang.String key, java.lang.String context, long timestamp)
java.util.concurrent.CompletableFuture<java.util.Optional<java.util.Optional<T>>>
getIfStaleAsync(java.lang.String key, java.lang.String context, long timestamp)
java.util.OptionalLong
getLastUpdated(java.lang.String key, java.lang.String context)
java.util.concurrent.CompletableFuture<java.util.OptionalLong>
getLastUpdatedAsync(java.lang.String key, java.lang.String context)
java.lang.String
getName()
long
put(java.lang.String key, T value, java.lang.String context)
long
put(java.lang.String key, T value, java.lang.String context, java.lang.Integer ttlInSeconds)
Put a value with a suggested time-to-live after which the value should be expired and removed from the store.java.util.concurrent.CompletableFuture<java.lang.Long>
putAsync(java.lang.String key, T value, java.lang.String context)
java.util.concurrent.CompletableFuture<java.lang.Long>
putAsync(java.lang.String key, T value, java.lang.String context, java.lang.Integer ttlInSeconds)
Put a value with a suggested time-to-live after which the value should be expired and removed from the store.void
truncateContext(java.lang.String context)
Remove all records for a given context.java.util.concurrent.CompletableFuture<java.lang.Void>
truncateContextAsync(java.lang.String context)
Remove all records for a given context.
-
-
-
Method Detail
-
put
long put(java.lang.String key, T value, java.lang.String context)
- Parameters:
context
- a context used to differentiate between keys with the same name (forms a compound key)- Returns:
- the timestamp the value was persisted with
-
put
long put(java.lang.String key, T value, java.lang.String context, java.lang.Integer ttlInSeconds)
Put a value with a suggested time-to-live after which the value should be expired and removed from the store.Records are expired on a best effort basis and depending on the implementation it is possible to get an expired record.
- Parameters:
context
- a context used to differentiate between keys with the same name (forms a compound key)ttlInSeconds
- the time to live in seconds for this key or no ttl if null- Returns:
- the timestamp the value was persisted with
-
get
java.util.Optional<T> get(java.lang.String key, java.lang.String context)
- Parameters:
context
- a context used to differentiate between keys with the same name (forms a compound key)- Returns:
- an optional containing the value if present or empty if the key did not exist
-
getIfStale
java.util.Optional<java.util.Optional<T>> getIfStale(java.lang.String key, java.lang.String context, long timestamp)
- Parameters:
context
- a context used to differentiate between keys with the same name (forms a compound key)timestamp
- the timestamp of the last known state such that if an record with a more recent timestamp is found the provided timestamp will be considered stale and the new record will be returned- Returns:
- an optional that will be empty if the key was not found or will contain another optional that will be empty if not stale or contain the value if stale
-
getLastUpdated
java.util.OptionalLong getLastUpdated(java.lang.String key, java.lang.String context)
- Parameters:
context
- a context used to differentiate between keys with the same name (forms a compound key)- Returns:
- an optional containing the timestamp the key's value was last updated or empty if the key did not exist
-
enumerateContext
java.util.Map<java.lang.String,T> enumerateContext(java.lang.String context)
- Parameters:
context
- a context used to differentiate between keys with the same name (forms a compound key)- Returns:
- a map of all the records matching the given context where the map's key is the record's key and the map's value is the records value
-
delete
void delete(java.lang.String key, java.lang.String context)
- Parameters:
context
- a context used to differentiate between keys with the same name (forms a compound key)
-
truncateContext
void truncateContext(java.lang.String context)
Remove all records for a given context.- Parameters:
context
- a context used to differentiate between keys with the same name (forms a compound key)
-
putAsync
java.util.concurrent.CompletableFuture<java.lang.Long> putAsync(java.lang.String key, T value, java.lang.String context)
- Parameters:
context
- a context used to differentiate between keys with the same name (forms a compound key)- Returns:
- a future containing the timestamp the value was persisted with
-
putAsync
java.util.concurrent.CompletableFuture<java.lang.Long> putAsync(java.lang.String key, T value, java.lang.String context, java.lang.Integer ttlInSeconds)
Put a value with a suggested time-to-live after which the value should be expired and removed from the store.Records are expired on a best effort basis and depending on the implementation it is possible to get an expired record.
- Parameters:
context
- a context used to differentiate between keys with the same name (forms a compound key)ttlInSeconds
- the time to live in seconds for this key or no ttl if null- Returns:
- a future containing the timestamp the value was persisted with
-
getAsync
java.util.concurrent.CompletableFuture<java.util.Optional<T>> getAsync(java.lang.String key, java.lang.String context)
- Parameters:
context
- a context used to differentiate between keys with the same name (forms a compound key)- Returns:
- a future containing an optional of the value if present or empty if the key did not exist
-
getIfStaleAsync
java.util.concurrent.CompletableFuture<java.util.Optional<java.util.Optional<T>>> getIfStaleAsync(java.lang.String key, java.lang.String context, long timestamp)
- Parameters:
context
- a context used to differentiate between keys with the same name (forms a compound key)timestamp
- the timestamp of the last known state such that if an record with a more recent timestamp is found the provided timestamp will be considered stale and the new record will be returned- Returns:
- a future containing an optional that will be empty if the key was not found or will contain another optional that will be empty if not stale or contain the value if stale
-
getLastUpdatedAsync
java.util.concurrent.CompletableFuture<java.util.OptionalLong> getLastUpdatedAsync(java.lang.String key, java.lang.String context)
- Parameters:
context
- a context used to differentiate between keys with the same name (forms a compound key)- Returns:
- a future containing an optional of the the timestamp the key's value was last updated or empty if the key did not exist
-
getName
java.lang.String getName()
- Returns:
- the name of the backing implementation
-
enumerateContextAsync
java.util.concurrent.CompletableFuture<java.util.Map<java.lang.String,T>> enumerateContextAsync(java.lang.String context)
- Parameters:
context
- a context used to differentiate between keys with the same name (forms a compound key)- Returns:
- a future containing a map of all the records matching the given context where the map's key is the record's key and the map's value is the records value
-
deleteAsync
java.util.concurrent.CompletableFuture<java.lang.Void> deleteAsync(java.lang.String key, java.lang.String context)
- Parameters:
context
- a context used to differentiate between keys with the same name (forms a compound key)- Returns:
- a future that is completed when the delete has finished
-
truncateContextAsync
java.util.concurrent.CompletableFuture<java.lang.Void> truncateContextAsync(java.lang.String context)
Remove all records for a given context.- Parameters:
context
- a context used to differentiate between keys with the same name (forms a compound key)
-
-