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.2.tar.gz (5.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.2-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyfastlru-1.0.2.tar.gz
  • Upload date:
  • Size: 5.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.2.tar.gz
Algorithm Hash digest
SHA256 06de279b43492ca12b7c56579aa6ab5d554ccd31403a42b849ea565f7bc9c530
MD5 6bbf98dc81dceb942b484eba57c5fdcb
BLAKE2b-256 f6f4aee66825e23327d0d132b337cf25ebfd42002ec87f036141f3ad07ce309a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyfastlru-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.7 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ab28054e9cdf4c7eed2eed2fcebf81c243f2422c81ecd796c404fcf74c35b823
MD5 737ef4db39089fe6f37f9ca84dc96fe2
BLAKE2b-256 8c45f0e9a70cb1e1b1a830400c90a66569f35575876680a6d51a9cdbdfe94182

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