Skip to content

Instantly share code, notes, and snippets.

@chaddotson
Created May 25, 2016 03:35
Show Gist options
  • Save chaddotson/7a7e758af9ea3de01ae8b3b3abde311f to your computer and use it in GitHub Desktop.
Save chaddotson/7a7e758af9ea3de01ae8b3b3abde311f to your computer and use it in GitHub Desktop.
Example of TTLCache from cachetools
from cachetools import TTLCache
from sched import scheduler
cache = TTLCache(maxsize=128, ttl=5)
runner = scheduler()
cache["abc"] = 42
def display_cached_value(cache_key):
try:
cached_value = cache[cache_key]
print("{0}={1}".format(cache_key, cached_value))
except KeyError:
print("{0}=Not in cache".format(cache_key))
runner.enter(2, 1, display_cached_value, argument=("abc",))
runner.enter(6, 1, display_cached_value, argument=("abc",))
runner.run()
@hugoalvarado
Copy link

import cachetools

@cachetools.cached(cachetools.TTLCache(10, 600))
def your_function():
pass

@anithj
Copy link

anithj commented Jun 8, 2020

can I cache 3 megabyte excel file using TTLCache????

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment