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

Documentation issues re: memoizing instance methods #554

Open
andreyfedoseev opened this issue Feb 7, 2024 · 0 comments
Open

Documentation issues re: memoizing instance methods #554

andreyfedoseev opened this issue Feb 7, 2024 · 0 comments

Comments

@andreyfedoseev
Copy link

I noticed two issues with documentation related to memoizing instance methods.

Consider the following case:

class MyClass:
   
    @cache.memoize
    def func(self, n):
        return n

According to the documentation, I should provide a class object to the delete_memoized function when a classmethod is memoized. The documentation does not mention instance methods there, so this implies that it isn't necessary in such case.

However, this does not work as expected (the cache is not invalidated):

my_instance = MyClass()
cache.delete_memoized(my_instance.func, 1)

Instead, one should do:

my_instance = MyClass()
cache.delete_memoized(my_instance.func, my_instance, 1)

This isn't documented, however.

Another issue related to that is that it is not possible to invalidate all cached calls of a method by calling delete_memoized without any arguments. It works with regular functions, but it won't work with class/instance methods since they require at least one argument when calling delete_memoized. This behavior isn't documented either.

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

No branches or pull requests

1 participant