[CMF-checkins] CVS: Products/CMFCore - FSImage.py:1.14 FSPageTemplate.py:1.18 utils.py:1.33

Andrew Sawyers andrew@zope.com
Thu, 14 Nov 2002 11:49:11 -0500


Update of /cvs-repository/Products/CMFCore
In directory cvs.zope.org:/tmp/cvs-serv3860/CMFCore

Modified Files:
	FSImage.py FSPageTemplate.py utils.py 
Log Message:
*Factored out _setCacheHeaders into the utils module
*Updated FSPageTemplate to import and call _setCacheHeaders from utils
*Added CMF cache policy manager awareness to FSImage - If associated with a ZCacheManager the ZCacheManager wins.


=== Products/CMFCore/FSImage.py 1.13 => 1.14 ===
--- Products/CMFCore/FSImage.py:1.13	Fri Nov  8 19:25:23 2002
+++ Products/CMFCore/FSImage.py	Thu Nov 14 11:49:10 2002
@@ -23,7 +23,7 @@
 from webdav.common import rfc1123_date
 from OFS.Image import Image, getImageInfo
 
-from utils import _dtmldir
+from utils import _dtmldir, _setCacheHeaders
 from CMFCorePermissions import ViewManagementScreens, View, FTPAccess
 from FSObject import FSObject
 from DirectoryView import registerFileExtension, registerMetaType, expandpath
@@ -116,11 +116,17 @@
                     RESPONSE.setStatus(304)
                     return ''
 
+        #Last-Modified will get stomped on by a cache policy it there is one set....
         RESPONSE.setHeader('Last-Modified', rfc1123_date(self._file_mod_time))
         RESPONSE.setHeader('Content-Type', self.content_type)
         RESPONSE.setHeader('Content-Length', len(data))
 
-        self.ZCacheable_set(None)
+        #There are 2 Cache Managers which can be in play....need to decide which to use
+        #to determine where the cache headers are decided on.
+        if self.ZCacheable_getManager() is not None:
+            self.ZCacheable_set(None)
+        else:
+            _setCacheHeaders(self, extra_context={})
         return data
 
     security.declareProtected(View, 'getContentType')


=== Products/CMFCore/FSPageTemplate.py 1.17 => 1.18 ===
--- Products/CMFCore/FSPageTemplate.py:1.17	Fri Nov  8 19:25:23 2002
+++ Products/CMFCore/FSPageTemplate.py	Thu Nov 14 11:49:10 2002
@@ -33,7 +33,7 @@
 from CMFCorePermissions import View
 from CMFCorePermissions import FTPAccess
 from FSObject import FSObject
-from utils import getToolByName
+from utils import getToolByName, _setCacheHeaders
 
 xml_detect_re = re.compile('^\s*<\?xml\s+')
 
@@ -116,22 +116,6 @@
         self._updateFromFS()
         return FSPageTemplate.inheritedAttribute('pt_macros')(self)
 
-    security.declarePrivate('_setCacheHeaders')
-    def _setCacheHeaders(self, extra_context):
-        """Set cache headers according to cache policy manager."""
-        REQUEST = getattr(self, 'REQUEST', None)
-        if REQUEST is not None:
-            content = aq_parent(self)
-            manager = getToolByName(content, 'caching_policy_manager', None)
-            if manager is not None:
-                view_name = self.getId()
-                headers = manager.getHTTPCachingHeaders(
-                                  content, view_name, extra_context
-                                  )
-                RESPONSE = REQUEST['RESPONSE']
-                for key, value in headers:
-                    RESPONSE.setHeader(key, value)
-
     def pt_render(self, source=0, extra_context={}):
         self._updateFromFS()  # Make sure the template has been loaded.
         try:
@@ -139,7 +123,7 @@
                                     self, source, extra_context
                                     )
             if not source:
-                self._setCacheHeaders(extra_context)
+                _setCacheHeaders(self, extra_context)
             return result
 
         except RuntimeError:


=== Products/CMFCore/utils.py 1.32 => 1.33 ===
--- Products/CMFCore/utils.py:1.32	Thu Nov 14 01:26:42 2002
+++ Products/CMFCore/utils.py	Thu Nov 14 11:49:10 2002
@@ -254,6 +254,22 @@
             something_changed = 1
     return something_changed
 
+security.declarePrivate('_setCacheHeaders')
+def _setCacheHeaders(obj, extra_context):
+    """Set cache headers according to cache policy manager for the obj."""
+    REQUEST = getattr(obj, 'REQUEST', None)
+    if REQUEST is not None:
+        obj = aq_parent(obj)
+        manager = getToolByName(obj, 'caching_policy_manager', None)
+        if manager is not None:
+            view_name = obj.getId()
+            headers = manager.getHTTPCachingHeaders(
+                              obj, view_name, extra_context
+                              )
+            RESPONSE = REQUEST['RESPONSE']
+            for key, value in headers:
+                RESPONSE.setHeader(key, value)
+
 #
 #   Base classes for tools
 #