Custom Mapping with TTL and LRU support.
Reason this release was yanked:
renamed
Project description
Python TTL Dict
Installation
Installation is available using pip install python_ttl_dict
.
Core Features
- TTL Dict: A thread-safe dictionary that automatically removes keys after a certain amount of time or if max size is reached.
- It can be used as a simple in-memory cache.
- Simple - The TTLDict derives MutableMapping and implements the same interface as the built-in dict class. It can be used as a drop-in replacement for dict.
- Efficient - The TTLDict is designed to be efficient in terms of both time and space complexity.
- Thread-safe - The TTLDict is thread-safe. It can be used in multithreaded applications without any additional synchronization.
- Lazy - The TTLDict is lazy. It does not spawn any additional threads or processes. Computing the time-to-live is done only when the TTLDict is accessed.
- Zero dependencies - The TTLDict has no dependencies other than the Python standard library.
- LRU support - The TTLDict supports LRU (least recently used) eviction policy. It can be configured to evict either the last set item or the least recently accessed item.
Usage Examples
from datetime import timedelta
from time import sleep
from ttlru_map import TTLDict
cache: TTLDict[str, str] = TTLDict(ttl=timedelta(seconds=10))
cache['key'] = 'value'
print(cache['key']) # 'value'
# Wait for 10 seconds
sleep(10)
print(cache['key']) # KeyError
If you want to add LRU functionality to your cache, you can maxsize
argument
from ttlru_map import TTLDict
cache: TTLDict[str, str] = TTLDict(ttl=None, max_size=2)
cache['key1'] = 'value1'
cache['key2'] = 'value2'
cache['key3'] = 'value3'
print(cache.get('key1')) # None
print(cache.get('key2')) # 'value2'
print(cache.get('key3')) # 'value3'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
ttlru_map-1.0-py3-none-any.whl
(13.4 kB
view details)
File details
Details for the file ttlru_map-1.0-py3-none-any.whl
.
File metadata
- Download URL: ttlru_map-1.0-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98f11212cb28ab30c35c721fcde0876e6795b63ba45054640c9316db8737939f |
|
MD5 | d3d24552596ed3064731f51f06874958 |
|
BLAKE2b-256 | c0c566a6309548e9379da13efb30ff1e829664ae744b7813f9432d506681e823 |