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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyfastlru-1.0.0.tar.gz.
File metadata
- Download URL: pyfastlru-1.0.0.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be2b0839534aa89a78d4d87d89d293c52211b9cb8190bb829749fc22c2bf270d
|
|
| MD5 |
306d1684fd4dc4a346b35fccc062d57c
|
|
| BLAKE2b-256 |
0245d6516d3fe811d2de55b9dcc04819653d1e762302411af66b58955917c96e
|
File details
Details for the file pyfastlru-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pyfastlru-1.0.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0666982963433bf8308eef18d3f2a8727f52c985d546729dd29488075c86d421
|
|
| MD5 |
4077050c6b36b53b1515f43cb458ad4a
|
|
| BLAKE2b-256 |
0d6cc4ca7e6081f29e190c4f01c6ef4681f96dbf51dda435cb8c26e155c6dc3d
|