[Checkins] SVN: z3c.jbot/trunk/z3c/jbot/ Added thread-local caching to quickly determine layer.

Malthe Borch mborch at gmail.com
Wed Jul 16 04:20:02 EDT 2008


Log message for revision 88395:
  Added thread-local caching to quickly determine layer.

Changed:
  U   z3c.jbot/trunk/z3c/jbot/Five.txt
  U   z3c.jbot/trunk/z3c/jbot/__init__.py

-=-
Modified: z3c.jbot/trunk/z3c/jbot/Five.txt
===================================================================
--- z3c.jbot/trunk/z3c/jbot/Five.txt	2008-07-16 03:17:39 UTC (rev 88394)
+++ z3c.jbot/trunk/z3c/jbot/Five.txt	2008-07-16 08:19:59 UTC (rev 88395)
@@ -97,6 +97,7 @@
 return the value that was set before the layer was provided.
   
   >>> interface.noLongerProvides(MockSite.REQUEST, ISpecificLayer)
+  >>> view.template._v_cache.layer = z3c.jbot.utility.getLayer()
   >>> view.template._v_last_read is not False
   True  
   

Modified: z3c.jbot/trunk/z3c/jbot/__init__.py
===================================================================
--- z3c.jbot/trunk/z3c/jbot/__init__.py	2008-07-16 03:17:39 UTC (rev 88394)
+++ z3c.jbot/trunk/z3c/jbot/__init__.py	2008-07-16 08:19:59 UTC (rev 88395)
@@ -1,3 +1,4 @@
+from zope import interface
 from zope.pagetemplate.pagetemplatefile import PageTemplateFile
 
 import utility
@@ -2,2 +3,3 @@
 import logging
+import threading
 
@@ -36,7 +38,7 @@
         
     def _get(self, template):
         key = self.name
-        layer = utility.getLayer()
+        layer = getattr(template._v_cache, 'layer', None)
         attrs = getattr(template, '_v_attrs', template.__dict__)
         if (layer, key) in attrs:
             return attrs[layer, key]
@@ -44,7 +46,7 @@
     
     def _set(self, template, value):
         key = self.name
-        layer = utility.getLayer()
+        layer = getattr(template._v_cache, 'layer', None)
         attrs = template.__dict__.get('_v_attrs')
         if attrs is None:
             attrs = template._v_attrs = {}
@@ -58,12 +60,15 @@
 # registration hook to template manager
 def jbot(func):
     def patch(self, *args, **kwargs):
+        # set layer
+        self._v_cache.layer = utility.getLayer()
+
         for manager in utility.getManagers():
             # register template; this call returns ``True`` if
             # template was invalidated
             if manager.registerTemplate(self):
                 break
-            
+        
         return func(self, *args, **kwargs)        
     return patch
 
@@ -79,3 +84,5 @@
                  '_v_last_read', '_v_warning', '_text_',
                  'filename', 'content_type', 'is_html'):
         setattr(pt_class, name, LayerProperty(pt_class, name))
+
+    setattr(pt_class, '_v_cache', threading.local())



More information about the Checkins mailing list