Package io.github.dhruv1110.jcachex.impl
Class WriteHeavyOptimizedCache<K,V>
- java.lang.Object
-
- io.github.dhruv1110.jcachex.impl.WriteHeavyOptimizedCache<K,V>
-
- All Implemented Interfaces:
Cache<K,V>
public final class WriteHeavyOptimizedCache<K,V> extends Object implements Cache<K,V>
Specialized write-heavy cache implementation optimized for write-intensive workloads. Key optimizations: - Asynchronous write operations - Write batching and coalescing - Optimized write-through and write-behind strategies - Minimal read-path interference - Write buffer management
-
-
Constructor Summary
Constructors Constructor Description WriteHeavyOptimizedCache(CacheConfig<K,V> config)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Removes all mappings from this cache.CompletableFuture<Void>
clearAsync()
Asynchronously removes all mappings from this cache.CacheConfig<K,V>
config()
Returns the cache configuration.boolean
containsKey(K key)
Returns true if this cache contains a mapping for the specified key.Set<Map.Entry<K,V>>
entries()
Returns a view of all the key-value pairs in this cache.void
flushWrites()
Flush all pending writes to main storage.V
get(K key)
Returns the value associated with the key in this cache, or null if there is no cached value for the key.CompletableFuture<V>
getAsync(K key)
Asynchronously returns the value associated with the key in this cache.int
getPendingWriteCount()
Get pending write count.long
getWriteCount()
Get write statistics.Set<K>
keys()
Returns a view of all the keys in this cache.void
put(K key, V value)
Associates the specified value with the specified key in this cache.CompletableFuture<Void>
putAsync(K key, V value)
Asynchronously associates the specified value with the specified key in this cache.V
remove(K key)
Removes the mapping for a key from this cache if it is present.CompletableFuture<V>
removeAsync(K key)
Asynchronously removes the mapping for a key from this cache if it is present.void
shutdown()
long
size()
Returns the approximate number of entries in this cache.CacheStats
stats()
Returns the cache statistics.Collection<V>
values()
Returns a view of all the values in this cache.
-
-
-
Constructor Detail
-
WriteHeavyOptimizedCache
public WriteHeavyOptimizedCache(CacheConfig<K,V> config)
-
-
Method Detail
-
get
public final V get(K key)
Description copied from interface:Cache
Returns the value associated with the key in this cache, or null if there is no cached value for the key.
-
put
public final void put(K key, V value)
Description copied from interface:Cache
Associates the specified value with the specified key in this cache.
-
remove
public final V remove(K key)
Description copied from interface:Cache
Removes the mapping for a key from this cache if it is present.
-
clear
public final void clear()
Description copied from interface:Cache
Removes all mappings from this cache.
-
size
public final long size()
Description copied from interface:Cache
Returns the approximate number of entries in this cache.
-
containsKey
public final boolean containsKey(K key)
Description copied from interface:Cache
Returns true if this cache contains a mapping for the specified key.- Specified by:
containsKey
in interfaceCache<K,V>
- Parameters:
key
- key whose presence in this cache is to be tested- Returns:
- true if this cache contains a mapping for the specified key
-
stats
public final CacheStats stats()
Description copied from interface:Cache
Returns the cache statistics.
-
config
public final CacheConfig<K,V> config()
Description copied from interface:Cache
Returns the cache configuration.
-
keys
public final Set<K> keys()
Description copied from interface:Cache
Returns a view of all the keys in this cache.
-
values
public final Collection<V> values()
Description copied from interface:Cache
Returns a view of all the values in this cache.
-
entries
public final Set<Map.Entry<K,V>> entries()
Description copied from interface:Cache
Returns a view of all the key-value pairs in this cache.
-
getAsync
public final CompletableFuture<V> getAsync(K key)
Description copied from interface:Cache
Asynchronously returns the value associated with the key in this cache.
-
putAsync
public final CompletableFuture<Void> putAsync(K key, V value)
Description copied from interface:Cache
Asynchronously associates the specified value with the specified key in this cache.
-
removeAsync
public final CompletableFuture<V> removeAsync(K key)
Description copied from interface:Cache
Asynchronously removes the mapping for a key from this cache if it is present.- Specified by:
removeAsync
in interfaceCache<K,V>
- Parameters:
key
- key whose mapping is to be removed from the cache- Returns:
- a CompletableFuture that will be completed with the previous value associated with key, or null if there was no mapping for key
-
clearAsync
public final CompletableFuture<Void> clearAsync()
Description copied from interface:Cache
Asynchronously removes all mappings from this cache.- Specified by:
clearAsync
in interfaceCache<K,V>
- Returns:
- a CompletableFuture that will be completed when the operation is done
-
flushWrites
public final void flushWrites()
Flush all pending writes to main storage.
-
getWriteCount
public final long getWriteCount()
Get write statistics.
-
getPendingWriteCount
public final int getPendingWriteCount()
Get pending write count.
-
shutdown
public final void shutdown()
-
-