Fix cache_multi_on_arguments when used on a class method

#14 Open

Bitbucket cannot automatically merge this request.

The commits that make up this pull request have been removed.

Bitbucket cannot automatically merge this request due to conflicts.

Review the conflicts on the Overview tab. You can then either decline the request or merge it manually on your local system using the following commands:

git checkout master
git remote add dairiki/dogpile.cache
git fetch dairiki/dogpile.cache
git merge --no-ff -m 'Merged in dairiki/dogpile.cache/bug.cache-multi-on-method (pull request #14)' remotes/dairiki/dogpile.cache/bug.cache-multi-on-method
  1. Jeff Dairiki

This patch fixes the CacheRegion.cache_multi_on_arguments decorator so that it will (mostly) work on class methods.

Some of these fixes are rather ugly. They would probably be prettier if function_multi_key_generator were dumbed down so that it doesn't try to ignore the first argument when the wrapped function appears to be a method, since we now have to add a dummy self argument when we call it from set, invalidate, and get.

Refresh is still broken for class methods. It might be possible to fix it by making the function_multi_key_generator return a property, but I say it's not worth it.

Comments (2)

  1. Jeff Dairiki author

    Yeah, the issue here is that cache_multi_on_arguments has to mangle the arguments which it passes on to the decorated function, removing those keys for which it has cached results. (Cache_on_arguments has a simpler time of it — it simple calls (or not) the wrapped function/method with the original arguments.)

    Function_multi_key_generator is currently method-aware, and when generating keys will ignore an initial self or cls argument, so that's half the battle. Cache_multi_on_arguments currently, however, never passes the self argument to the decorated method. It always calls the function. The crux is here:

        def creator(*keys_to_create):
            return fn(*[key_lookup[k] for k in keys_to_create])