Interface BaseStore
- All Known Implementing Classes:
InMemoryStore
public interface BaseStore
Abstract interface for a namespace-based key-value store.
Items are organized by namespaces (hierarchical path-like tuples) and identified by a key within each namespace.
-
Method Summary
Modifier and TypeMethodDescriptionvoidDelete an item by namespace and key.Get a single item by namespace and key.voidStore or update an item.default booleanConditional update: stores the item only when the current stored version matchesexpectedVersion.Search for items within a namespace with pagination.
-
Method Details
-
get
Get a single item by namespace and key.- Parameters:
namespace- hierarchical namespace pathkey- the item key within the namespace- Returns:
- the store item, or
nullif not found
-
put
Store or update an item.- Parameters:
namespace- hierarchical namespace pathkey- the item key within the namespacevalue- the data to store
-
putIfVersion
default boolean putIfVersion(List<String> namespace, String key, Map<String, Object> value, long expectedVersion) Conditional update: stores the item only when the current stored version matchesexpectedVersion.This is a compare-and-swap (CAS) operation that prevents lost updates when multiple writers concurrently modify the same key. Callers should:
- Read the item with
get(java.util.List<java.lang.String>, java.lang.String)and rememberStoreItem.version(). - Compute the new value locally.
- Call
putIfVersionpassing the remembered version asexpectedVersion. - If the call returns
false, the item was modified by another writer; retry from step 1.
A special value of
0forexpectedVersionmeans "write only if the key does not yet exist" (i.e. create-if-absent).The default implementation always returns
falseso that existing store implementations compile without changes. Backends that support distributed deployments should override this method with a proper server-side atomic check.- Parameters:
namespace- hierarchical namespace pathkey- the item key within the namespacevalue- the new data to storeexpectedVersion- the version the caller observed; must match the current stored version- Returns:
trueif the item was written,falseif the version did not match
- Read the item with
-
search
Search for items within a namespace with pagination.- Parameters:
namespace- hierarchical namespace pathlimit- maximum number of items to returnoffset- number of items to skip- Returns:
- list of matching store items
-
delete
Delete an item by namespace and key.- Parameters:
namespace- hierarchical namespace pathkey- the item key to delete
-