Class AbstractOffHeapClockCache<K,V>

Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values
All Implemented Interfaces:
ConcurrentMap<K,V>, ReadWriteLock, Map<K,V>, HashingMap<K,V>, MapInternals, PinnableCache<K,V>, PinnableSegment<K,V>, Segment<K,V>, StorageEngine.Owner
Direct Known Subclasses:
AbstractPersistentOffHeapCache, ReadWriteLockedOffHeapClockCache, WriteLockedOffHeapClockCache

public abstract class AbstractOffHeapClockCache<K,V> extends AbstractLockedOffHeapHashMap<K,V> implements PinnableCache<K,V>, PinnableSegment<K,V>
An abstract off-heap cache implementation.

Subclasses must implement the two getEvictionIndex(...) methods to instruct the cache regarding which mappings to remove.

  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • PRESENT_CLOCK

      private static final int PRESENT_CLOCK
      See Also:
    • rndm

      private final Random rndm
    • clockHand

      private int clockHand
  • Constructor Details

    • AbstractOffHeapClockCache

      public AbstractOffHeapClockCache(PageSource source, StorageEngine<? super K, ? super V> storageEngine)
    • AbstractOffHeapClockCache

      public AbstractOffHeapClockCache(PageSource source, boolean tableAllocationsSteal, StorageEngine<? super K, ? super V> storageEngine)
    • AbstractOffHeapClockCache

      public AbstractOffHeapClockCache(PageSource source, StorageEngine<? super K, ? super V> storageEngine, boolean bootstrap)
    • AbstractOffHeapClockCache

      public AbstractOffHeapClockCache(PageSource source, StorageEngine<? super K, ? super V> storageEngine, int tableSize)
    • AbstractOffHeapClockCache

      public AbstractOffHeapClockCache(PageSource source, boolean tableAllocationsSteal, StorageEngine<? super K, ? super V> storageEngine, int tableSize)
    • AbstractOffHeapClockCache

      public AbstractOffHeapClockCache(PageSource source, StorageEngine<? super K, ? super V> storageEngine, int tableSize, boolean bootstrap)
  • Method Details

    • storageEngineFailure

      protected void storageEngineFailure(Object failure)
      Overrides:
      storageEngineFailure in class OffHeapHashMap<K,V>
    • tableExpansionFailure

      protected void tableExpansionFailure(int start, int length)
      Overrides:
      tableExpansionFailure in class OffHeapHashMap<K,V>
    • hit

      protected void hit(int position, IntBuffer entry)
      Overrides:
      hit in class OffHeapHashMap<K,V>
    • getEvictionIndex

      public int getEvictionIndex()
      Return the table offset of the to be evicted mapping.

      The mapping to be evicted can occur anywhere in this cache's table.

      Returns:
      table offset of the mapping to be evicted
    • getEvictionIndex

      private int getEvictionIndex(int start, int length)
      Return the table offset of the to be evicted mapping within the given probe sequence.

      The mapping to be evicted must occur within the given probe sequence.

      Parameters:
      start - initial slot in probe sequence
      length - number of slots in probe sequence
      Returns:
      table offset of the mapping to be evicted
    • evictable

      protected boolean evictable(int status)
    • evict

      public boolean evict(int index, boolean shrink)
      Specified by:
      evict in interface StorageEngine.Owner
      Overrides:
      evict in class AbstractLockedOffHeapHashMap<K,V>
    • isPinned

      public boolean isPinned(Object key)
      Specified by:
      isPinned in interface PinnableCache<K,V>
    • setPinning

      public void setPinning(K key, boolean pinned)
      Specified by:
      setPinning in interface PinnableCache<K,V>
    • putPinned

      public V putPinned(K key, V value)
      Specified by:
      putPinned in interface PinnableCache<K,V>
    • getAndPin

      public V getAndPin(K key)
      Specified by:
      getAndPin in interface PinnableCache<K,V>