A least recently used (LRU) cache implementation with time to live (TTL)
Project description
Introduction
This is a Python LRU cache implementation with TTL support, this way you can ensure you will not get results older than the specified TTL.
Installation
pip install lru-ttl
How to use
>>> from lruttl import LRUCache
>>> cache = LRUCache(10)
>>> cache.set('key1', ['some object'], 5)
>>> cache['key1']
['some object']
>>> # wait a couple of seconds
>>> cache['key1']
>>> cache = LRUCache(2)
>>> cache.set('key1', 'val1')
>>> cache.set('key2', 'val2')
>>> cache.set('key3', 'val3')
>>> 'key1' in cache
False
>>> 'key2' in cache
True
>>> 'key3' in cache
True
The TTL does not have precedence, so the last recently used keys will be evicted first!
>>> cache = LRUCache(2)
>>> cache.set('key1', 'val1')
>>> cache.set('key2', 'val2', 10000)
>>> cache.set('key3', 'val3')
>>> 'key1' in cache
False
>>> 'key2' in cache
True
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 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 lru-ttl-0.0.7.tar.gz.
File metadata
- Download URL: lru-ttl-0.0.7.tar.gz
- Upload date:
- Size: 2.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8467356458bb4fcf709b12d3c092e5423b4c51206309c26d27d04ab4754c2c13
|
|
| MD5 |
5dae4770258eb2023caf53ac06c2ac4e
|
|
| BLAKE2b-256 |
2417cf89a7106f13af6eb5eb122632f0629090cfd39f2a605229958c0bec62d7
|
File details
Details for the file lru_ttl-0.0.7-py3-none-any.whl.
File metadata
- Download URL: lru_ttl-0.0.7-py3-none-any.whl
- Upload date:
- Size: 3.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36a53ab5adeb3a3bcac7aaa8e19dbd40464b3b62dc8820eb73c6c89baacbcd2b
|
|
| MD5 |
23ba65d4270431e7dad6c609a17096d2
|
|
| BLAKE2b-256 |
0ed8068be7acf0ce85568bc3d9c44b8412b579e0bc943d2b8ca0cbaf5863233e
|