selectors.py
changeset 5881 57387070f612
parent 5877 0c7b7b76a84f
child 5890 141b935a38fc
--- a/selectors.py	Mon Jul 05 13:34:29 2010 +0200
+++ b/selectors.py	Mon Jul 05 13:35:15 2010 +0200
@@ -202,7 +202,8 @@
 
 from yams import BASE_TYPES
 
-from cubicweb import Unauthorized, NoSelectableObject, NotAnEntity, role
+from cubicweb import (Unauthorized, NoSelectableObject, NotAnEntity,
+                      CW_EVENT_MANAGER, role)
 # even if not used, let yes here so it's importable through this module
 from cubicweb.appobject import Selector, objectify_selector, lltrace, yes
 from cubicweb.schema import split_expression
@@ -698,6 +699,10 @@
             score += score_interface(etypesreg, cls_or_inst, cls, iface)
         return score
 
+def _reset_is_instance_cache(vreg):
+    vreg._is_instance_selector_cache = {}
+
+CW_EVENT_MANAGER.bind('before-registry-reset', _reset_is_instance_cache)
 
 class is_instance(EClassSelector):
     """Return non-zero score for entity that is an instance of the one of given
@@ -728,10 +733,7 @@
 
     def score_etypes(self, req, cls_or_inst, cls):
         # cache on vreg to avoid reloading issues
-        try:
-            cache = req.vreg.__is_instance_cache
-        except AttributeError:
-            cache = req.vreg.__is_instance_cache = {}
+        cache = req.vreg._is_instance_selector_cache
         try:
             expected_eclasses = cache[self]
         except KeyError: