Class NearCache<K,V>
java.lang.Object
com.loomcache.client.cache.NearCache<K,V>
- Type Parameters:
K- key typeV- value type
Client-side near-cache for frequently accessed entries.
Stores frequently accessed cache entries locally to reduce network round-trips. Supports configurable max size, TTL, and eviction policies (LRU, LFU, Random). Thread-safe using ConcurrentHashMap with minimal locking for eviction.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordCache efficiency metrics.static final recordCache entry metadata.static interfaceInterface for eviction policies.static final recordConfiguration for NearCache.static final recordNear cache statistics. -
Constructor Summary
ConstructorsConstructorDescriptionNearCache(NearCache.NearCacheConfig config) Create a new near cache with the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoidClear all statistics.@Nullable VGet a value from the cache.Get cache efficiency metrics.Get detailed cache statistics.@Nullable NearCache.CacheEntryMetadatagetEntryMetadata(K key) Get metadata for a cache entry.Get the current eviction policy name.getStats()Get cache statistics.voidinvalidate(K key) Invalidate a single key.voidInvalidate all entries.voidPreload multiple entries into the cache.voidPut a key-value pair into the cache.voidRemove a key from the cache.voidSet the eviction policy.voidshutdown()Shutdown the cache and cleanup resources.intsize()Get cache size.
-
Constructor Details
-
NearCache
Create a new near cache with the given configuration.- Parameters:
config- the near cache configuration (must not be null)- Throws:
NullPointerException- if config is null
-
-
Method Details
-
get
-
put
-
remove
Remove a key from the cache. -
invalidate
Invalidate a single key. -
invalidateAll
public void invalidateAll()Invalidate all entries. -
size
public int size()Get cache size. -
getStats
Get cache statistics. -
getDetailedStats
Get detailed cache statistics. -
clearStats
public void clearStats()Clear all statistics. -
preload
-
getEvictionPolicy
Get the current eviction policy name.- Returns:
- the eviction policy name
-
setEvictionPolicy
Set the eviction policy.- Parameters:
policy- the new eviction policy
-
getEntryMetadata
Get metadata for a cache entry.- Parameters:
key- the key to look up- Returns:
- cache entry metadata or null if not found
-
getCacheEfficiency
Get cache efficiency metrics.- Returns:
- cache efficiency metrics
-
shutdown
public void shutdown()Shutdown the cache and cleanup resources.
-