Skip to main content

LRUCache

Attempt to reimplement LRUCache from @apify/datastructures using OrderedDict.

Index

Methods

__delitem__

  • __delitem__(*, key): None
  • Remove an item from the cache.


    Parameters

    • optionalkeyword-onlykey: str

    Returns None

__getitem__

  • __getitem__(*, key): T
  • Get an item from the cache. Move it to the end if present.


    Parameters

    • optionalkeyword-onlykey: str

    Returns T

__init__

  • __init__(*, max_length): None
  • A default constructor.


    Parameters

    • optionalkeyword-onlymax_length: int

      The maximum number of items to store in the cache.

    Returns None

__iter__

  • __iter__(): Iterator[str]
  • Iterate over the keys of the cache in order of insertion.


    Returns Iterator[str]

__len__

  • __len__(): int
  • Get the number of items in the cache.


    Returns int

__setitem__

  • __setitem__(*, key, value): None
  • Add an item to the cache. Remove least used item if max_length exceeded.


    Parameters

    • optionalkeyword-onlykey: str
    • optionalkeyword-onlyvalue: T

    Returns None

items

  • items(): ItemsView[str, T]
  • Iterate over the pairs of (key, value) in the cache in order of insertion.


    Returns ItemsView[str, T]

values

  • values(): ValuesView[T]
  • Iterate over the values in the cache in order of insertion.


    Returns ValuesView[T]