Skip to main content

Python implementation of a thread-safe LRU cache.

Project description

pyfastlru v. 1.0

Python implementation of a thread-safe LRU cache.

Features: thread safety, statistics, familiar interface.

The MIT License (MIT). Copyright © 2025 Anatoly Petrov petrov.projects@gmail.com

Description

LRU cache is a data structure that combines fast item access by the key with invalidation of least recently used items in case of size limit exhaustion.

These traits make the LRU cache useful for memoizing some computations (requests, resources, etc.) without risking memory blowup.

Our implementation uses a doubly linked list for item usage tracking and a dict for the lookup table.

Overview

The cache provides a MutableMapping interface. Thus, you may use LruCache the same way you use dict.

Unlike the standard dict (which is unbounded), the cache size is limited by the maxsize value provided to the cache __init__ method (128 by default). If the item count exceeds the limit,LruCache automatically removes the least recently used item.

Synchronization is performed internally by the cache with a reentrant lock and doesn't require any actions from the end-user.

Manual synchronization with LruCache context protocol or acquire/release methods is needed only to implement the atomic operations.

Cache collects usage statistics (hits, misses, maxsize, currsize) which may be retrieved with the cache_info() method.

Testing

pyfastlru is tested with pytest framework.

License

pyfastlru is licensed under the MIT License, see LICENSE for more information.

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

pyfastlru-1.0.1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

pyfastlru-1.0.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file pyfastlru-1.0.1.tar.gz.

File metadata

  • Download URL: pyfastlru-1.0.1.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for pyfastlru-1.0.1.tar.gz
Algorithm Hash digest
SHA256 680d3b9fe055e8864409fe80198e1821377c8bc72e949b771082d42202b4faac
MD5 e602dc44ea9adc3491facb455d5393e5
BLAKE2b-256 ac0d551ed6483f96775c8fd81b90b63841a84766feb189fb4a86b6cda664da8c

See more details on using hashes here.

File details

Details for the file pyfastlru-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pyfastlru-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for pyfastlru-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 37bca1bdae91b1494fcf588a2c45b4ed862820b98dddffcc0216a7f8cef11f33
MD5 91dc12cedfd9133233bf4136aae0a080
BLAKE2b-256 19f233f4c4c0335796cf116edf4cea322e9080695b6d5d7d78c4178e7f321c83

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