LRUCache

dotty.tools.dotc.util.LRUCache
See theLRUCache companion object
class LRUCache[Key >: Null <: AnyRef, Value >: Null]

A least-recently-used cache for Key -> Value computations It currently keeps the last 8 associations, but this can be changed to anywhere between 2 and 16 by changing LRUCache.Retained.

Implementation: We keep a ring of eight places, linked with the next data structure. The ring models a priority queue. last points to the last element of the queue, and next(last) to the first one. Lookups compare keys sequentially from first to last. Elements with successful lookup get promoted to be first in the queue. Elements are evicted at the last position.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def enter(key: Key, value: Value): Unit

Enter key/value in cache at position last. As a side effect, sets last to lastButOne. If lastButOne was set by a preceding unsuccessful lookup for the same key, this means that the new element is now the first in the queue. If there was no preceding lookup, the element is inserted at a random position in the queue.

Enter key/value in cache at position last. As a side effect, sets last to lastButOne. If lastButOne was set by a preceding unsuccessful lookup for the same key, this means that the new element is now the first in the queue. If there was no preceding lookup, the element is inserted at a random position in the queue.

Attributes

def first: Int
def invalidate(key: Key): Unit

Invalidate key. The invalidated element becomes the last in the queue.

Invalidate key. The invalidated element becomes the last in the queue.

Attributes

def lookup(key: Key): Value

Lookup key, returning value or null for not found. As a side effect, sets lastButOne to the element before last if key was not found.

Lookup key, returning value or null for not found. As a side effect, sets lastButOne to the element before last if key was not found.

Attributes

override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any

Concrete fields

val keys: Array[Key]
var last: Int
val values: Array[Value]