Opened 7 years ago

Closed 7 years ago

#14278 closed enhancement (fixed)

Clear the cache of a cached representation

Reported by: SimonKing Owned by: jason
Priority: major Milestone: sage-5.9
Component: misc Keywords:
Cc: Merged in: sage-5.9.beta2
Authors: Simon King Reviewers: Travis Scrimshaw
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: #14054 Stopgaps:

Description

I have seen doctests that try to demonstrate how to clear a cache of class instances. See sage/modular/abvar/abvar_ambient_jacobian.py, for example.

This made me think: It would be nice to be able to define a class method for CachedRepresentation that clears the cache from all instances of this class.

With my patch, the following works:

            sage: class A(UniqueRepresentation):
            ...    def __init__(self, x):
            ...        pass
            sage: class B(A):
            ...    @staticmethod
            ...    def __classcall__(cls, *args, **kwds):
            ...        return super(B,cls).__classcall__(cls,*args,**kwds)
            sage: class C(B): pass
            sage: a = A(1)
            sage: b = B(2)
            sage: c = C(3)
            sage: a is A(1)
            True
            sage: b is B(2)
            True
            sage: c is C(3)
            True
            sage: B._clear_cache_()
            sage: a is A(1)
            True
            sage: b is B(2)
            False
            sage: c is C(3)
            False

Note that B overloads __classcall__, but nevertheless the _clear_cache_ methods finds the cache and removes all instances of B and its subclass C.

Sorry, I have no idea what component to choose. Let it be misc, then...

Attachments (2)

trac_14278-clear_cached_presentation.patch (2.8 KB) - added by SimonKing 7 years ago.
trac_14278-doctest.patch (1.6 KB) - added by SimonKing 7 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 7 years ago by SimonKing

  • Status changed from new to needs_review

Changed 7 years ago by SimonKing

comment:2 Changed 7 years ago by SimonKing

I updated the patch: The additional (class) method made one test in my coercion tutorial fail, that tests for the number of methods.

comment:3 Changed 7 years ago by SimonKing

The failure reported be one of the patchbots was a maxima crash. I suppose that's unrelated. In any case, I kicked the bot, so, we will see of the maxima crash is reproducible.

comment:4 Changed 7 years ago by SimonKing

Hooray, we now have a green blob!

comment:5 Changed 7 years ago by tscrim

Hey Simon,

Could you also add tests with a __classcall_private__()? Thanks.

Changed 7 years ago by SimonKing

comment:6 Changed 7 years ago by SimonKing

Is the test that I added in my second patch appropriate?

Apply trac_14278-clear_cached_presentation.patch trac_14278-doctest.patch

comment:7 Changed 7 years ago by tscrim

  • Reviewers set to Travis Scrimshaw
  • Status changed from needs_review to positive_review

Yep. Looks good to me. Thank you.

comment:8 Changed 7 years ago by jdemeyer

  • Merged in set to sage-5.9.beta2
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.