Skip to main content

LRU caching with expiration period.

Project description

logo

expiring_lru_cache

Maintained by dataroots Python versions PiPy Downloads Code style: black Mypy checked Codecov test

expiring_lru_cache is a minimal drop-in replacement of functools.lru_cache. It allows the user to specify a time interval (in secs) after which the cache is invalidated and reset.

Usage

Here an example cached function whose cache will invalidate after 10 seconds.

from expiring_lru_cache import lru_cache

@lru_cache(expires_after=10)
def my_plus_one_func(x: int) -> int:
    return x + 1

Here an example cached function whose cache will invalidate after 1 day. Note that the convenience variables MINUTES, HOURS and DAYS are available within the expiring_lru_cache namespace.

from expiring_lru_cache import lru_cache, DAYS


@lru_cache(expires_after=1 * DAYS)
def my_plus_one_func(x: int) -> int:
    return x + 1

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

expiring_lru_cache-0.1.0.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

expiring_lru_cache-0.1.0-py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 3

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