Package io.github.dhruv1110.jcachex.impl
Class DefaultCache<K,V>
- java.lang.Object
-
- io.github.dhruv1110.jcachex.impl.base.AbstractCacheBase<K,V>
-
- io.github.dhruv1110.jcachex.impl.base.DataBackedCacheBase<K,V,CacheEntry<V>>
-
- io.github.dhruv1110.jcachex.impl.base.ConcurrentCacheBase<K,V>
-
- io.github.dhruv1110.jcachex.impl.DefaultCache<K,V>
-
- Type Parameters:
K
- the type of keys maintained by this cacheV
- the type of mapped values
- All Implemented Interfaces:
Cache<K,V>
,AutoCloseable
public class DefaultCache<K,V> extends ConcurrentCacheBase<K,V> implements AutoCloseable
Default implementation of the Cache interface.This implementation is thread-safe and supports various cache configurations including eviction strategies, expiration policies, and event listeners. It provides both synchronous and asynchronous operations for maximum flexibility.
Performance Optimizations: This implementation uses striped locking to reduce contention, optimized expiration checks using nanoTime, and minimizes object allocation in hot paths.
- Since:
- 1.0.0
- See Also:
CacheConfig
,CacheEventListener
-
-
Field Summary
-
Fields inherited from class io.github.dhruv1110.jcachex.impl.base.ConcurrentCacheBase
currentSize, currentWeight, evictionStrategy, scheduler, STRIPE_COUNT, stripes
-
Fields inherited from class io.github.dhruv1110.jcachex.impl.base.DataBackedCacheBase
data
-
Fields inherited from class io.github.dhruv1110.jcachex.impl.base.AbstractCacheBase
config, hasExpiration, hasMaximumSize, hasMaximumWeight, hitCount, maximumSize, missCount, stats, statsEnabled
-
-
Constructor Summary
Constructors Constructor Description DefaultCache(CacheConfig<K,V> config)
Creates a new DefaultCache with the specified configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes this cache and releases any resources associated with it.protected void
scheduleRefresh()
Schedule refresh operations for entries that support refresh.-
Methods inherited from class io.github.dhruv1110.jcachex.impl.base.ConcurrentCacheBase
cleanupExpiredEntries, createCacheEntry, createCacheEntry, doClear, doContainsKey, doGet, doPut, doRemove, enforceSize, evictEntries, evictEntries, extractValue, getCurrentWeight, getReadLock, getStripeIndex, getWriteLock, isValidEntry, loadValue, notifyListeners, recordScheduledTask, refreshEntries, scheduleCleanup, shouldAvoidEvictingNewEntries, shutdown, size
-
Methods inherited from class io.github.dhruv1110.jcachex.impl.base.DataBackedCacheBase
afterClear, beforeClear, createMapEntry, entries, getDataMap, isValidValue, keys, values
-
Methods inherited from class io.github.dhruv1110.jcachex.impl.base.AbstractCacheBase
clear, clearAsync, config, containsKey, get, getAsync, isEntryExpired, isSizeLimitReached, put, putAsync, recordClearStatistics, recordGetStatistics, recordPutStatistics, recordRemoveStatistics, remove, removeAsync, stats, updateStatsFromCounters, validateKey, validateValue
-
-
-
-
Constructor Detail
-
DefaultCache
public DefaultCache(CacheConfig<K,V> config)
Creates a new DefaultCache with the specified configuration.
-
-
Method Detail
-
scheduleRefresh
protected void scheduleRefresh()
Schedule refresh operations for entries that support refresh.- Overrides:
scheduleRefresh
in classConcurrentCacheBase<K,V>
-
close
public void close()
Closes this cache and releases any resources associated with it.- Specified by:
close
in interfaceAutoCloseable
-
-