Skip to main content

Python implementation of LRU Cache

Project description

lru-od

Python implementation of LRU-Cache using OrderedDict

Installing

Python 3.7 or higher required!

To install the stable version of the library:

# on linux/macOS
python3 -m pip install lru-od

# windows
py -3 -m pip install lru-od

To install the development version of the library:

$ git clone https://github.com/XiehCanCode/lru-od
$ cd lru-od
$ python3 -m pip install -U .

Example

from lru import LRUCache

cache: LRUCache[str, str] = LRUCache(max_size=2)
cache.set("foo", "bar") # you can also use: cache['foo'] = 'bar'
cache.set("bar", "foo")
print(cache.get("foo")) # this key-pair would be pushed to end
cache.set("ping", "pong") # since we're exceeding the max size, the least used will be removed, in this case it's {'bar': 'foo'}

API

  • class LRUCache
    LRU Cache implementation

    Parameters

    max_size: Optional[int]
    Max size of the cache, default's to 120

    Operations

    x == y
    x != y
    x in y

    Methods

    • cache_info() -> str
      Information about the cache
    • get(key: Any) -> Any | None
      Get a value of the key-value pair with given key if exists
    • items() -> tuple[Any, Any]
      D.values() -> a set-like object providing a view on D's items
    • keys() -> KeysView[Any]
      D.keys() -> a set-like object providing a view on D's keys
    • remove(key: Any) -> None
      Remove a key-value pair associated with the key parameter if exists
    • set(key: Any, value: Any) -> dict[Any, Any]
      Set/Update a new/existing key-value pair with given key and pair and returns the key-value pair created/updated
    • values() -> ValuesView[Any]
      D.values() -> a set-like object providing a view on D's values

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lru-od-0.0.1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lru_od-0.0.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file lru-od-0.0.1.tar.gz.

File metadata

  • Download URL: lru-od-0.0.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

File hashes

Hashes for lru-od-0.0.1.tar.gz
Algorithm Hash digest
SHA256 0b81a191e02ccfdd5c6512f0011152d548eac2d5b156024854198cad22607731
MD5 aeb9df2dad32f1055012e923c701b44e
BLAKE2b-256 aa2b940d172f3b4d5c4856532fa7a5cc168f62fa6c41f99972ed569f2b920b57

See more details on using hashes here.

File details

Details for the file lru_od-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: lru_od-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

File hashes

Hashes for lru_od-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 72e72a58c04f5d6142a847170459332c5a10866f93a12f907c520a961be4b684
MD5 40b7081d30b3cb603a707f2f7806d8a2
BLAKE2b-256 c361a123569385dec77e2dd55ab0e819a8742d167172021f1c58d46973b961c0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page