Skip to main content

Simple TTL Cache for methods and there results.

Project description

Python Method Cache

Build Status PyPI version Documentation Status

What it does

MethodCache can be used to cache the result of an method in a flexible way. This libary has no dependencies!

Currently only TTL Cache available

The cache storage can be segmented in categories. Methods with the @cache decorator are saved in these categories.

Example

from methodcache import cache, Store
import time

# TTL in Seconds (Default TTl is 60)
st = Store(ttl=60*300)

# Define Store for this Cache, and overwrite Store TTL. And categorize this cache object to demo
@cache(store=st, ttl=5, category="demo")
def doothings(a,b,c):
    # Do here what ever you want.
    # eg. MySQL querys or other slow operations
    time.sleep(2)
    return a+b+c

# Slow Execution
doothings(1,2,3)
# Slow Execution

doothings(4,5,6)

# Fast Execution because the Cache was used
doothings(1,2,3)
time.sleep(2)

# Slow Execution because the Cache TTL is Expired
doothings(1,2,3)

Documentation

Read the Docs

or show example.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

method_cache-1.0.4.tar.gz (5.3 kB view details)

Uploaded Source

File details

Details for the file method_cache-1.0.4.tar.gz.

File metadata

  • Download URL: method_cache-1.0.4.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.3

File hashes

Hashes for method_cache-1.0.4.tar.gz
Algorithm Hash digest
SHA256 993f26d552af44a4f8b3b34f52320f4b7102a3ac76bda2e1a924022eb7e3470a
MD5 ca611959341e9686cec716a4120c15c8
BLAKE2b-256 d5b76afcec7f501b02dbed7f5221e6b4aeddca3011ccf93ae76b314f14c6dc86

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