Class WriteBehindCache<K,V>
java.lang.Object
com.loomcache.client.cache.WriteBehindCache<K,V>
- Type Parameters:
K- key typeV- value type
Write-behind cache that buffers writes and flushes asynchronously using a daemon thread.
Writes are queued and flushed in batches to reduce load on the backend. Multiple writes to the same key are coalesced — only the last value is flushed. Automatic flushing occurs at configurable intervals.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordConfiguration for WriteBehindCache.static interfaceCallback interface for flushing writes to the backend. -
Constructor Summary
ConstructorsConstructorDescriptionWriteBehindCache(WriteBehindCache.WriteBehindConfig config, WriteBehindCache.WriteFlushCallback<K, V> flushCallback) Create a new write-behind cache. -
Method Summary
-
Constructor Details
-
WriteBehindCache
public WriteBehindCache(WriteBehindCache.WriteBehindConfig config, WriteBehindCache.WriteFlushCallback<K, V> flushCallback) Create a new write-behind cache.- Parameters:
config- the write-behind configuration (must not be null)flushCallback- the callback to flush writes to backend (must not be null)- Throws:
NullPointerException- if any parameter is null
-
-
Method Details
-
start
public void start()Start the write-behind background thread. -
put
Queue a write. Returns immediately.- Parameters:
key- the key to writevalue- the value to write- Throws:
IllegalStateException- if the cache is closed or queue is full
-
flush
-
close
-
getPendingCount
public int getPendingCount()Get the number of pending writes. -
isRunning
public boolean isRunning()Check if the cache is running.
-