Class WriteBehindCache<K,V>

java.lang.Object
com.loomcache.client.cache.WriteBehindCache<K,V>
Type Parameters:
K - key type
V - value type

public class WriteBehindCache<K,V> extends Object
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.

  • Constructor Details

  • Method Details

    • start

      public void start()
      Start the write-behind background thread.
    • put

      public void put(K key, V value)
      Queue a write. Returns immediately.
      Parameters:
      key - the key to write
      value - the value to write
      Throws:
      IllegalStateException - if the cache is closed or queue is full
    • flush

      public void flush() throws Exception
      Flush all pending writes immediately.
      Throws:
      Exception - if flushing fails
    • close

      public void close() throws Exception
      Close the cache and flush all pending writes.
      Throws:
      Exception - if final flush fails
    • getPendingCount

      public int getPendingCount()
      Get the number of pending writes.
    • isRunning

      public boolean isRunning()
      Check if the cache is running.