Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to do ttl_cache + custom key ? #146

Closed
wimglenn opened this issue Sep 26, 2019 · 2 comments
Closed

How to do ttl_cache + custom key ? #146

wimglenn opened this issue Sep 26, 2019 · 2 comments

Comments

@wimglenn
Copy link
Contributor

Thanks for your work on this clean and cool library!

I like being able to specify the hash key with

@cached(cache, key=mykey)

I also like the cachetool.func conveniences such as

@ttl_cache(maxsize=512, ttl=60*5)

Could you add a bit more feature parity in these interfaces? E.g. a way to specify the hashkey for @ttl_cache and/or a way to specify a ttl for @cached. Cheers.

@tkem
Copy link
Owner

tkem commented Sep 27, 2019

The cachetools.func decorators are there to mimic the standard library functools.lru_cache, mostly to provide some sort of migration path. So no, sorry, you're limited to typed=True or typed=False regarding choice of hash key, to keep it simple.

@wimglenn
Copy link
Contributor Author

OK, no problem. It ends up being pretty clean anyway with the existing APIs:

from cachetools import cached 
from cachetools.ttl import TTLCache   
cache = TTLCache(maxsize=512, ttl=60*5)   

@cached(cache, key=mykey)
def myfunc(...):
    ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants