Module openj9.dtfj

Class AbstractLruCache

  • All Implemented Interfaces:
    Serializable
    Direct Known Subclasses:
    ObjectLruCache

    public abstract class AbstractLruCache
    extends AbstractHashMap
    This class is the superclass of the LRU cache classes. It provides the LRU (Least Recently Used) infrastructure to map integer keys to objects or primitive values. It acts just like a hash map except that once it has reached its maximum size, any further puts will displace the least recently used entry. It uses a doubly linked list to keep track of which entries are most used - an entry is moved to the front of the list every time it is used. Note that the LRU info is lost when the cache is rehashed, but I don't think that's a problem because once the cache reaches its maximum size (and steady state) it will no longer rehash.
    See Also:
    Serialized Form
    • Constructor Detail

      • AbstractLruCache

        protected AbstractLruCache​(int maxSize)
        Create a new AbstractLruCache.
        Parameters:
        maxSize - the maximum size the cache can grow to
    • Method Detail

      • getIndexAndPromote

        protected int getIndexAndPromote​(long key)
        Returns the index for the value mapped by the given key. Also promotes this key to the most recently used.
        Returns:
        the index or -1 if it cannot be found
      • putIndexAndPromote

        protected int putIndexAndPromote​(long key)
        Get the index for a put operation. Takes care of promotion and removing the LRU entry if necessary.