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 timedcache

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.0.tar.gz (3.7 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: py-timed-cache-1.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 f42d0c5d3f86c6248004febf97cbfb7bde71159d31768f3ce1be6d81338afce8
MD5 9c5bf727672cf21c548647bc4c387d88
BLAKE2b-256 e24a508a786d5aec7057906fe51fde423fe5019db41b52a20158fb1f2786d251

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