Skip to content

Documentation issues re: memoizing instance methods #554

@andreyfedoseev

Description

@andreyfedoseev

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions