Record Class MapStoreBackedCacheWriter<K,V>

java.lang.Object
java.lang.Record
com.loomcache.server.jcache.MapStoreBackedCacheWriter<K,V>
Type Parameters:
K - the key type
V - the value type
All Implemented Interfaces:
CacheWriterIntegration.BackingStoreWriter<K,V>

public record MapStoreBackedCacheWriter<K,V>(MapStore<K,V> mapStore) extends Record implements CacheWriterIntegration.BackingStoreWriter<K,V>
Adapter that exposes a MapStore as a CacheWriterIntegration.BackingStoreWriter, letting JCache (JSR-107) write-through / write-behind reuse the same SPI as DistributedMap.setMapStore(MapStore, MapStoreConfig).

The adapter intentionally delegates ONLY write(Object, Object)BackingStoreWriter is a single-method functional interface; CacheWriterIntegration does not model a delete path today. Deletes continue to flow through whatever JCache-side CacheWriter configuration callers wire up.

Write-behind double-buffering warning. When this adapter wraps a MapStore that is already configured for write-behind on a DistributedMap, and the surrounding CacheWriterIntegration is ALSO created in write-behind mode, writes traverse two independent schedulers (the JCache queue, then the DistributedMap queue) with two batch/flush cycles, two retry budgets and two sets of metrics. That configuration is legal but rarely what operators want. Prefer one of:

  • Configure JCache write-behind and wrap a MapStore that uses MapStoreConfig.writeThroughConfig() — JCache owns the async semantics, the store sees synchronous calls.
  • Configure JCache write-through and let a write-behind MapStoreConfig own the async semantics.

The adapter is thread-safe iff the wrapped MapStore is, which is a hard requirement of the MapStore SPI contract.

  • Constructor Details

  • Method Details

    • write

      public void write(K key, V value)
      Delegate a write to MapStore.store(Object, Object). The CacheWriterIntegration contract forbids null key/value, so we pass through and let the store enforce its own invariants.
      Specified by:
      write in interface CacheWriterIntegration.BackingStoreWriter<K,V>
      Parameters:
      key - the key (never null when invoked through CacheWriterIntegration.write(Object, Object))
      value - the value (never null when invoked through CacheWriterIntegration.write(Object, Object))
    • mapStore

      public MapStore<K,V> mapStore()
      Expose the underlying MapStore for diagnostics / advanced callers that need to issue reads or deletes outside the CacheWriterIntegration write path.
      Returns:
      the wrapped store (never null)
    • load

      public @Nullable V load(K key)
      Load a value via the wrapped MapStore. Convenience for callers that want the adapter to also serve read-through semantics without reaching into ().
      Parameters:
      key - the key to look up (never null)
      Returns:
      the value loaded from the store, or null when absent
    • delete

      public void delete(K key)
      Delete a key via the wrapped MapStore. Convenience for callers that want the adapter to also serve write-through-deletes without reaching into (). Not invoked by CacheWriterIntegration itself — that class has no delete path.
      Parameters:
      key - the key to delete (never null)
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.