class documentation

class LRUCache: (source)

View In Hierarchy

A simple LRU Cache implementation.

Method __contains__ Check if a key exists in this cache.
Method __delitem__ Remove an item from the cache dict. Raise a `KeyError` if it does not exist.
Method __getitem__ Get an item from the cache. Moves the item up so that it has the highest priority then.
Method __getnewargs__ Undocumented
Method __getstate__ Undocumented
Method __init__ Undocumented
Method __iter__ Undocumented
Method __len__ Return the current size of the cache.
Method __repr__ Undocumented
Method __reversed__ Iterate over the keys in the cache dict, oldest items coming first.
Method __setitem__ Sets the value for an item. Moves the item up so that it has the highest priority then.
Method __setstate__ Undocumented
Method clear Clear the cache.
Method copy Return a shallow copy of the instance.
Method get Return an item from the cache dict or `default`
Method items Return a list of items.
Method keys Return a list of all keys ordered by most recent usage.
Method setdefault Set `default` if the key is not in the cache otherwise leave unchanged. Return the value of this key.
Method values Return a list of all values.
Instance Variable capacity Undocumented
Method _postinit Undocumented
Instance Variable _append Undocumented
Instance Variable _mapping Undocumented
Instance Variable _pop Undocumented
Instance Variable _popleft Undocumented
Instance Variable _queue Undocumented
Instance Variable _remove Undocumented
Instance Variable _wlock Undocumented
def __contains__(self, key): (source)

Check if a key exists in this cache.

Parameters
key:t.AnyUndocumented
Returns
boolUndocumented
def __delitem__(self, key): (source)

Remove an item from the cache dict. Raise a `KeyError` if it does not exist.

Parameters
key:t.AnyUndocumented
def __getitem__(self, key): (source)

Get an item from the cache. Moves the item up so that it has the highest priority then. Raise a `KeyError` if it does not exist.

Parameters
key:t.AnyUndocumented
Returns
t.AnyUndocumented
def __getnewargs__(self): (source)

Undocumented

Returns
t.TupleUndocumented
def __getstate__(self): (source)

Undocumented

Returns
t.Mapping[str, t.Any]Undocumented
def __init__(self, capacity): (source)

Undocumented

Parameters
capacity:intUndocumented
def __iter__(self): (source)

Undocumented

Returns
t.Iterator[t.Any]Undocumented
def __len__(self): (source)

Return the current size of the cache.

Returns
intUndocumented
def __repr__(self): (source)

Undocumented

Returns
strUndocumented
def __reversed__(self): (source)

Iterate over the keys in the cache dict, oldest items coming first.

Returns
t.Iterator[t.Any]Undocumented
def __setitem__(self, key, value): (source)

Sets the value for an item. Moves the item up so that it has the highest priority then.

Parameters
key:t.AnyUndocumented
value:t.AnyUndocumented
def __setstate__(self, d): (source)

Undocumented

Parameters
d:t.Mapping[str, t.Any]Undocumented
def clear(self): (source)

Clear the cache.

def copy(self): (source)

Return a shallow copy of the instance.

Returns
LRUCacheUndocumented
def get(self, key, default=None): (source)

Return an item from the cache dict or `default`

Parameters
key:t.AnyUndocumented
default:t.AnyUndocumented
Returns
t.AnyUndocumented
def items(self): (source)

Return a list of items.

Returns
t.Iterable[t.Tuple[t.Any, t.Any]]Undocumented
def keys(self): (source)

Return a list of all keys ordered by most recent usage.

Returns
t.Iterable[t.Any]Undocumented
def setdefault(self, key, default=None): (source)

Set `default` if the key is not in the cache otherwise leave unchanged. Return the value of this key.

Parameters
key:t.AnyUndocumented
default:t.AnyUndocumented
Returns
t.AnyUndocumented
def values(self): (source)

Return a list of all values.

Returns
t.Iterable[t.Any]Undocumented
capacity = (source)

Undocumented

def _postinit(self): (source)

Undocumented

_append = (source)

Undocumented

Undocumented

_pop = (source)

Undocumented

_popleft = (source)

Undocumented

_queue: te.Deque[t.Any] = (source)

Undocumented

_remove = (source)

Undocumented

_wlock = (source)

Undocumented