Interface MapStore<K,V>

Type Parameters:
K - the key type
V - the value type
All Known Subinterfaces:
EntryStore<K,V>
All Known Implementing Classes:
JCacheWriterToMapStoreAdapter, JdbcGenericMapStore

public interface MapStore<K,V>
Service Provider Interface (SPI) for plugging an external persistent backing store into a DistributedMap.

Implementations are expected to be thread-safe: LoomCache invokes the store from multiple threads (write-behind flusher + user-visible ops when write-through is enabled) and never serializes access internally.

Failures are surfaced as unchecked exceptions to the caller when the store is configured for write-through; under write-behind they are caught and counted into CacheMetrics.writeThroughFailureCount() / CacheMetrics.deleteThroughFailureCount().

Default loadAll / storeAll / deleteAll / loadAllKeys implementations are provided so that minimal stores only need to implement the three single-key methods.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    delete(K key)
    Remove a single key from the backing store.
    default void
    deleteAll(Collection<? extends K> keys)
    Remove multiple keys.
    @Nullable V
    load(K key)
    Load the value associated with key from the backing store.
    default Map<K,V>
    loadAll(Collection<? extends K> keys)
    Load multiple values in one round-trip.
    default Iterable<K>
    Stream every key known to the backing store.
    void
    store(K key, V value)
    Persist a single key/value pair.
    default void
    storeAll(Map<? extends K, ? extends V> map)
    Persist multiple key/value pairs.
  • Method Details

    • load

      @Nullable V load(K key)
      Load the value associated with key from the backing store.
      Parameters:
      key - the key to look up (never null)
      Returns:
      the associated value, or null when no value exists
    • loadAll

      default Map<K,V> loadAll(Collection<? extends K> keys)
      Load multiple values in one round-trip. Default implementation loops load(Object); override for efficiency when the store supports bulk reads.
      Parameters:
      keys - keys to load (never null; may contain no duplicates)
      Returns:
      a map containing only keys for which a non-null value was loaded
    • loadAllKeys

      default Iterable<K> loadAllKeys()
      Stream every key known to the backing store. Used for EAGER preload. Default returns an empty iterable, which disables EAGER preload.
      Returns:
      an iterable over all persisted keys
    • store

      void store(K key, V value)
      Persist a single key/value pair.
      Parameters:
      key - the key (never null)
      value - the value to persist (never null)
    • storeAll

      default void storeAll(Map<? extends K, ? extends V> map)
      Persist multiple key/value pairs. Default implementation loops store(Object, Object); override for efficiency when the store supports bulk writes.
      Parameters:
      map - entries to persist (never null)
    • delete

      void delete(K key)
      Remove a single key from the backing store. No-op when the key is absent.
      Parameters:
      key - the key to delete (never null)
    • deleteAll

      default void deleteAll(Collection<? extends K> keys)
      Remove multiple keys. Default implementation loops delete(Object); override for efficiency when the store supports bulk deletes.
      Parameters:
      keys - keys to delete (never null)