Class OptimizedCacheBase<K,​V>

  • Type Parameters:
    K - the type of keys maintained by this cache
    V - the type of mapped values
    All Implemented Interfaces:
    Cache<K,​V>
    Direct Known Subclasses:
    AllocationOptimizedCache, JITOptimizedCache, OptimizedCache

    public abstract class OptimizedCacheBase<K,​V>
    extends ConcurrentCacheBase<K,​V>
    Base class for optimized cache implementations providing performance-oriented features. This class extends ConcurrentCacheBase and adds: - Lock-free read operations where possible - Frequency sketching for access patterns - Batched operations to reduce contention - Adaptive eviction strategies - Performance monitoring and optimization
    • Constructor Detail

      • OptimizedCacheBase

        protected OptimizedCacheBase​(CacheConfig<K,​V> config)
        Constructor for optimized cache implementations.
        Parameters:
        config - the cache configuration
    • Method Detail

      • doGet

        protected V doGet​(K key)
        Optimized get operation with lock-free reads where possible.
        Overrides:
        doGet in class ConcurrentCacheBase<K,​V>
        Parameters:
        key - the key (already validated)
        Returns:
        the value or null if not found/expired
      • doPut

        protected void doPut​(K key,
                             V value)
        Optimized put operation with batched processing.
        Overrides:
        doPut in class ConcurrentCacheBase<K,​V>
        Parameters:
        key - the key (already validated)
        value - the value (already validated)
      • enforceSize

        protected void enforceSize()
        Optimized size enforcement using advanced eviction strategies.
        Overrides:
        enforceSize in class ConcurrentCacheBase<K,​V>
      • recordAccess

        protected void recordAccess​(K key,
                                    AccessBuffer.AccessType type,
                                    int frequency)
        Records access for frequency analysis and batched processing.
      • scheduleEviction

        protected void scheduleEviction()
        Schedules eviction using the optimized strategy.
      • drainAccessBuffer

        protected void drainAccessBuffer()
        Drains the access buffer and updates eviction state.
      • processAccessRecord

        protected void processAccessRecord​(AccessBuffer.AccessRecord<K> record)
        Processes an access record for eviction strategy updates.
      • scheduleOptimizationTasks

        protected void scheduleOptimizationTasks()
        Schedules periodic optimization tasks.
      • performPeriodicMaintenance

        protected void performPeriodicMaintenance()
        Performs periodic maintenance and optimization.
      • getPerformanceMetrics

        public String getPerformanceMetrics()
        Returns performance metrics for monitoring.
      • shutdown

        public void shutdown()
        Shuts down the optimized cache and cleans up resources.
        Overrides:
        shutdown in class ConcurrentCacheBase<K,​V>
      • performCustomOptimization

        protected void performCustomOptimization()
        Hook for subclasses to perform custom optimization.
      • getVersion

        protected long getVersion()
        Returns the current version for optimistic concurrency control.
      • shouldAvoidEvictingNewEntries

        protected boolean shouldAvoidEvictingNewEntries()
        Determines if we should avoid evicting newly added entries. FILO and FIFO strategies should not avoid evicting new entries.
        Overrides:
        shouldAvoidEvictingNewEntries in class ConcurrentCacheBase<K,​V>