Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lru-ttl-0.0.7.tar.gz (2.1 kB view details)

Uploaded Source

Built Distribution

lru_ttl-0.0.7-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

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

Hashes for lru-ttl-0.0.7.tar.gz
Algorithm Hash digest
SHA256 8467356458bb4fcf709b12d3c092e5423b4c51206309c26d27d04ab4754c2c13
MD5 5dae4770258eb2023caf53ac06c2ac4e
BLAKE2b-256 2417cf89a7106f13af6eb5eb122632f0629090cfd39f2a605229958c0bec62d7

See more details on using hashes here.

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

Hashes for lru_ttl-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 36a53ab5adeb3a3bcac7aaa8e19dbd40464b3b62dc8820eb73c6c89baacbcd2b
MD5 23ba65d4270431e7dad6c609a17096d2
BLAKE2b-256 0ed8068be7acf0ce85568bc3d9c44b8412b579e0bc943d2b8ca0cbaf5863233e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page