Skip to main content

LRUCache

crawlee._utils.lru_cache.LRUCache

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

Index

Constructors

__init__

  • __init__(max_length): None
  • Create a LRUCache with a specific max_length.


    Parameters

    • max_length: int

    Returns None

Methods

__delitem__

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


    Parameters

    • key: str

    Returns None

__getitem__

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


    Parameters

    • key: str

    Returns T

__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

    • key: str
    • value: 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]