Class ClockProPlusEviction

  • All Implemented Interfaces:
    NeedsClose, Eviction

    public class ClockProPlusEviction
    extends AbstractEviction
    Eviction algorithm inspired from CLOCK Pro with 3 clocks.

    Uses a static allocation for hot and cold space sizes. No online or dynamic optimization is done yet. However, the hit rate for all measured access traces is better than LRU and resistant to scans.

    From cache2k version 1.2 to version 1.4 the implementation was simplified and the demotion of hot entries removed. The result achieves similar or better hit rates. Version 2.4 limits the ghost size to 3000 elements. Version 2.6 stops inserting evicted hot entries into ghosts.

    The Clock-Pro algorithm is explained by the authors in CLOCK-Pro: An Effective Improvement of the CLOCK Replacement and Clock-Pro: An Effective Replacement in OS Kernel.

    Author:
    Jens Wilke
    • Constructor Detail

    • Method Detail

      • getHotMax

        public long getHotMax()
      • getGhostMax

        public long getGhostMax()
      • updateHotMax

        protected void updateHotMax()
        Updates hot max based on current size. This is called when eviction kicks in so current size is the maximum size this cache should reach regardless whether we use entry capacity or weigher to limit the size.
        Specified by:
        updateHotMax in class AbstractEviction
      • removeFromReplacementList

        protected void removeFromReplacementList​(Entry e)
        Remove, expire or eviction of an entry happens. Remove the entry from the replacement list data structure.

        Why don't generate ghosts here? If the entry is removed because of a programmatic remove or expiry we should not occupy any resources. Removing and expiry may also take place when no eviction is needed at all, which happens when the cache size did not hit the maximum yet. Producing ghosts would add additional overhead, when it is not needed.

        Specified by:
        removeFromReplacementList in class AbstractEviction
      • findIdleCandidate

        protected Entry findIdleCandidate​(int maxScan)
        Find idle candidate. Idle scanning does scan on the bigger clock first, which is typically the hot clock, because entries are sitting in the cache for the longest time.
        Specified by:
        findIdleCandidate in class AbstractEviction
      • findIdleInHot

        protected Entry findIdleInHot​(int maxScan)
      • checkIntegrity

        public void checkIntegrity​(IntegrityState integrityState)