dogpile.cache icon indicating copy to clipboard operation
dogpile.cache copied to clipboard

method support in function_key_generator / function_multi_key_generator

Open sqlalchemy-bot opened this issue 8 years ago • 9 comments

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.

sqlalchemy-bot avatar Mar 11 '16 16:03 sqlalchemy-bot

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.

sqlalchemy-bot avatar Mar 11 '16 16:03 sqlalchemy-bot

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.

sqlalchemy-bot avatar Mar 12 '16 10:03 sqlalchemy-bot

Michael Bayer (zzzeek) wrote:

see https://bitbucket.org/zzzeek/dogpile.cache/pull-requests/14/fix-cache_multi_on_arguments-when-used-on/diff

sqlalchemy-bot avatar Nov 16 '18 00:11 sqlalchemy-bot

Michael Bayer (zzzeek) wrote:

Issue #133 was marked as a duplicate of this issue.

sqlalchemy-bot avatar Nov 16 '18 01:11 sqlalchemy-bot

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.

sqlalchemy-bot avatar Nov 16 '18 19:11 sqlalchemy-bot

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.

sqlalchemy-bot avatar Nov 16 '18 19:11 sqlalchemy-bot

Changes by Michael Bayer (zzzeek):

  • edited description

sqlalchemy-bot avatar Nov 16 '18 00:11 sqlalchemy-bot

Changes by Michael Bayer (zzzeek):

  • changed title from "method support in function_key_generator" to "method support in function_key_generator / https:/"

sqlalchemy-bot avatar Nov 16 '18 00:11 sqlalchemy-bot

Changes by Michael Bayer (zzzeek):

  • changed title from "method support in function_key_generator / https:/" to "method support in function_key_generator / functio"

sqlalchemy-bot avatar Nov 16 '18 00:11 sqlalchemy-bot