Package io.github.dhruv1110.jcachex.impl
Class AllocationOptimizedCache<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.base.OptimizedCacheBase<K,V>
-
- io.github.dhruv1110.jcachex.impl.AllocationOptimizedCache<K,V>
-
- All Implemented Interfaces:
Cache<K,V>
public final class AllocationOptimizedCache<K,V> extends OptimizedCacheBase<K,V>
Allocation-optimized cache implementation that minimizes object allocation overhead. Key optimizations: - Thread-local object pools for frequently created objects - Eliminates boxing/unboxing in critical paths - Reduces intermediate object creation - Reuses objects instead of creating new ones - Zero-allocation hot paths where possible
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.github.dhruv1110.jcachex.impl.base.OptimizedCacheBase
OptimizedCacheBase.State
-
-
Field Summary
-
Fields inherited from class io.github.dhruv1110.jcachex.impl.base.OptimizedCacheBase
accessBuffer, DEFAULT_DRAIN_INTERVAL_NANOS, DEFAULT_DRAIN_THRESHOLD, FREQUENCY_SKETCH_SIZE, frequencySketch, maintenanceLock, operationState, version, windowTinyLFUStrategy
-
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 AllocationOptimizedCache(CacheConfig<K,V> config)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected CacheEntry<V>
createCacheEntry(V value)
Override to use pooled entry creation for allocation optimization.String
getAllocationMetrics()
Returns allocation-specific performance metrics.protected void
performCustomOptimization()
Performs allocation-specific optimizations.void
shutdown()
Override shutdown to clean up thread-local pools.-
Methods inherited from class io.github.dhruv1110.jcachex.impl.base.OptimizedCacheBase
doClear, doGet, doPut, drainAccessBuffer, enforceSize, getOperationState, getPerformanceMetrics, getVersion, performPeriodicMaintenance, processAccessRecord, recordAccess, scheduleEviction, scheduleOptimizationTasks, shouldAvoidEvictingNewEntries
-
Methods inherited from class io.github.dhruv1110.jcachex.impl.base.ConcurrentCacheBase
cleanupExpiredEntries, createCacheEntry, doContainsKey, doRemove, evictEntries, evictEntries, extractValue, getCurrentWeight, getReadLock, getStripeIndex, getWriteLock, isValidEntry, loadValue, notifyListeners, recordScheduledTask, refreshEntries, scheduleCleanup, scheduleRefresh, 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
-
AllocationOptimizedCache
public AllocationOptimizedCache(CacheConfig<K,V> config)
-
-
Method Detail
-
createCacheEntry
protected CacheEntry<V> createCacheEntry(V value)
Override to use pooled entry creation for allocation optimization.- Overrides:
createCacheEntry
in classConcurrentCacheBase<K,V>
- Parameters:
value
- the value to wrap- Returns:
- a new cache entry
-
performCustomOptimization
protected void performCustomOptimization()
Performs allocation-specific optimizations.- Overrides:
performCustomOptimization
in classOptimizedCacheBase<K,V>
-
shutdown
public void shutdown()
Override shutdown to clean up thread-local pools.- Overrides:
shutdown
in classOptimizedCacheBase<K,V>
-
getAllocationMetrics
public String getAllocationMetrics()
Returns allocation-specific performance metrics.
-
-