[Zodb-checkins] CVS: Zope3/src/zope/interface - adapter.py:1.6.24.2

Jim Fulton jim at zope.com
Sat Oct 11 11:14:25 EDT 2003


Update of /cvs-repository/Zope3/src/zope/interface
In directory cvs.zope.org:/tmp/cvs-serv15898/src/zope/interface

Modified Files:
      Tag: adaptergeddon-branch
	adapter.py 
Log Message:
Restored adapter caching using declarations as cache keys directly.


=== Zope3/src/zope/interface/adapter.py 1.6.24.1 => 1.6.24.2 ===
--- Zope3/src/zope/interface/adapter.py:1.6.24.1	Sat Oct 11 10:19:03 2003
+++ Zope3/src/zope/interface/adapter.py	Sat Oct 11 11:14:24 2003
@@ -77,6 +77,9 @@
             raise TypeError(
                 "The provide argument must be an interface")
 
+        # Invalidate our cache
+        self._v_cache = {}
+
         self._registerAllProvided(require, provide, object, provide)
 
     def get(self, ob_interface_provide, default=None, filter=None):
@@ -84,6 +87,21 @@
         Finds a registered component that provides the given interface.
         Returns None if not found.
         """
+
+        if filter is None:
+            cache = getattr(self, '_v_cache', self)
+            if cache is self:
+                cache = self._v_cache = {}
+
+            # get the cache key
+            key = ob_interface_provide
+
+            cached = cache.get(key, self)
+            if cached is self:
+                cached = self._uncached_get(ob_interface_provide,
+                                            default, filter)
+                cache[key] = cached
+            return cached
 
         return self._uncached_get(ob_interface_provide,
                                   default, filter)




More information about the Zodb-checkins mailing list