Registry / serialization / repoze.lru

repoze.lru

JSON →
library0.8pypypi✓ verified 33d ago

repoze.lru is a light-weight LRU (Least Recently Used) cache implementation for Python, including both an `LRUCache` object and an `lru_cache` decorator. It efficiently evicts less frequently used keys and values to manage memory. The current version 0.7, released in 2017, maintains a stable and slow release cadence, focusing on core functionality.

pip install repoze.lru
INSTALL
IMPORT
SIG · REPOZE.LRU
R
repoze.lru
serializationpythonv0.8
Install
1.5s avg
Import
12ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.8 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.014s · 17.8MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.010s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LRUCache
✓ from repoze.lru import LRUCache
lru_cache
✓ from repoze.lru import lru_cache
✗ from functools import lru_cache
repoze.lru.lru_cache is a separate implementation. It does not support keyword arguments and has different behavior compared to the built-in functools.lru_cache (Python 3.2+).

Demonstrates how to create and use an `LRUCache` object, and how to apply the `lru_cache` decorator to a function.

from repoze.lru import LRUCache, lru_cache # Using LRUCache object cache = LRUCache(100) # Max length of 100 items cache.put('key1', 'value1') print(f"Cache get 'key1': {cache.get('key1')}") print(f"Cache get 'nonexisting' with default: {cache.get('nonexisting', 'default_value')}") # Using lru_cache decorator @lru_cache(50) def expensive_function(arg1, arg2): print(f"Executing expensive_function({arg1}, {arg2})") return arg1 + arg2 print(f"Result 1: {expensive_function(1, 2)}") # Executes print(f"Result 2: {expensive_function(1, 2)}") # Cached print(f"Result 3: {expensive_function(3, 4)}") # Executes
Debug
Known issues
gotchaThe `lru_cache` decorator from `repoze.lru` explicitly does not support keyword arguments for decorated functions. All arguments must be positional.
fix
Ensure all arguments to functions decorated with `repoze.lru.lru_cache` are passed positionally. If keyword argument support is needed, consider `functools.lru_cache` (Python 3+) or alternative caching libraries.
affects: 0.1 - 0.7
breakingVersions prior to 0.5 contained known thread safety issues and potential race conditions in `LRUCache.put()` and cache clearing logic. These could lead to incorrect cache state or performance degradation under concurrent access.
fix
Upgrade to `repoze.lru` version 0.5 or newer to benefit from fixes for thread safety and race conditions. This is critical for applications using the cache in multi-threaded environments.
affects: < 0.5
gotchaUsing `lru_cache` (or any `lru_cache` implementation) directly on instance methods of a class can lead to memory leaks. The cache will hold a strong reference to `self` (the instance) for each unique set of arguments, preventing instances from being garbage collected even after they are no longer actively used.
fix
To cache instance methods, consider applying `lru_cache` to a wrapper function inside the `__init__` method, using a weak reference, or refactoring the logic into a static/module-level function that takes necessary instance data as arguments.
affects: 0.1 - 0.7 (general LRU cache design issue)
gotchaThe `repoze.lru` library officially supports Python 2.7 and Python 3.4+. While earlier Python 3 versions (e.g., 3.2) were mentioned in older documentation, relying on these for current development with version 0.7 might lead to unexpected issues.
fix
Ensure your project's Python environment is 2.7 or 3.4+ for full compatibility and tested behavior with `repoze.lru`.
affects: All versions, specifically Python 3.0-3.3
Upgrade
Version history
0.8latest on PyPI · released May 16, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
Amazon
1
OpenAI (training)
1
Resources
repoze.lru — pip install repoze.lru · libregistry