Skip to main content

Pure Python timed-cache

Project description

timed-cache

Pure Python timed-cache that behaves like a regular dict. Can also be used as a decorator to cache function calls (works for async functions as well).

Installation

pip install py-timed-cache

Example

from timedcache import TimedCache

my_cache = TimedCache(1) # 1 second cache
my_cache["foo"] = "bar" # all dict methods works as if it was a normal dict
for k, v in my_cache.items():
    print(k, v) # will print foo bar

# Also works for functions

@TimedCache(5)
def foo(number):
    # some expensive compute...
    print("begin computation...")
    result = number * 10**30
    print("end computation")
    return res

big_number = foo(42) # cache MISS ==> this will print both statements above

big_number_again = foo(42) # Called with same argument(s) ==> cache HIT, returns immediately

Python versions

Python >= 3.6 are supported

Tests

This project uses unittest.

Run python tests/test_timedcache.py

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

py-timed-cache-1.0.2.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file py-timed-cache-1.0.2.tar.gz.

File metadata

  • Download URL: py-timed-cache-1.0.2.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for py-timed-cache-1.0.2.tar.gz
Algorithm Hash digest
SHA256 c30445220261a2fa2c049f51648b22af94b1273bde1e3f2f189c3e4012f2b89e
MD5 d15d16012f65d12b14a7be05ccd1aef2
BLAKE2b-256 8f87e717964fe732bf0bc83396458d01d99654772b5ed722b6574486a3134efc

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