#14278: Clear the cache of a cached representation
---------------------------+------------------------------------------------
   Reporter:  SimonKing    |             Owner:  jason     
       Type:  enhancement  |            Status:  new       
   Priority:  major        |         Milestone:  sage-5.9  
  Component:  misc         |          Keywords:            
Work issues:               |   Report Upstream:  N/A       
  Reviewers:               |           Authors:  Simon King
  Merged in:               |      Dependencies:  #14054    
   Stopgaps:               |  
---------------------------+------------------------------------------------
 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...

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/14278>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to