dogpile.cache
dogpile.cache copied to clipboard
method support in function_key_generator / function_multi_key_generator
Migrated issue, originally created by Wolfgang Schnerring (wosc)
It would be nice if function_key_generator
would support methods in addition to plain functions.
An example implementation is here: https://github.com/ZeitOnline/pyramid_dogpile_cache2/blob/1.0.1/src/pyramid_dogpile_cache2/cache.py#L26
I haven't found a way to do this other than computing the namespace
during each function call (instead of only once and storing it in the closure), since at definition time I think you don't have enough information about the function etc. available.
Michael Bayer (zzzeek) wrote:
classmethods or instancemethods? the former is very hard. look through the PRs for various handwringing over this. this is why the function is pluggable.
Wolfgang Schnerring (wosc) wrote:
I was thinking of instancemethods. But you're right, individual usecases probably vary a lot, so it's a good thing it's pluggable.
Michael Bayer (zzzeek) wrote:
see https://bitbucket.org/zzzeek/dogpile.cache/pull-requests/14/fix-cache_multi_on_arguments-when-used-on/diff
Krishna Vudata (kvudata) wrote:
It would be ideal to at least raise an error rather than try to incorrectly handle class methods in function_multi_key_generator
- right now it will just silently give you back wrong results.
Michael Bayer (zzzeek) wrote:
Can you propose a patch which makes this possible? IIRC the issue is we don't know that this callable is a classmethod or not and we have no way to know what this argument is or not.
Changes by Michael Bayer (zzzeek):
- changed title from "method support in function_key_generator" to "method support in function_key_generator / https:/"
Changes by Michael Bayer (zzzeek):
- changed title from "method support in function_key_generator / https:/" to "method support in function_key_generator / functio"