[Zope-CVS] CVS: Products/FileCacheManager - FileCacheManager.py:1.2

Chris McDonough chrism at plope.com
Sun Mar 28 01:15:25 EST 2004


Update of /cvs-repository/Products/FileCacheManager
In directory cvs.zope.org:/tmp/cvs-serv10692

Modified Files:
	FileCacheManager.py 
Log Message:
Return a StreamIterator rather than a producer; delete some unused code.


=== Products/FileCacheManager/FileCacheManager.py 1.1.1.1 => 1.2 ===
--- Products/FileCacheManager/FileCacheManager.py:1.1.1.1	Sun Mar 21 19:15:32 2004
+++ Products/FileCacheManager/FileCacheManager.py	Sun Mar 28 01:15:24 2004
@@ -10,11 +10,10 @@
 
 from BTrees import OOBTree
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
-from ZServer.medusa.producers import file_producer
+from ZPublisher.Iterators import filestream_iterator
 from Products.StandardCacheManagers.RAMCacheManager import RAMCache, \
      CacheEntry, RAMCacheManager
 from Acquisition import aq_base
-from OFS.Image import fcplaceholder
 
 caches = {}
 
@@ -31,25 +30,8 @@
         self._makeDirs()
 
     def _fileName(self, ob):
-        """ Compute a filename for the given object.
-        We must base the filename on the getPhysicalPath, 
-        otherwise there is too great a chance of the object being
-        accessed from two places, or two objects using the same cache.
-
-        Code swiped from FSCacheManager.
-        """
-
-        phys_path = '/'.join(ob.getPhysicalPath())[1:]
-        if self._dir is None:
-            raise ValueError, 'No directory has been selected'
-        fn = os.path.join(self._dir, phys_path)
-        # windows fix
-        fn = os.path.normpath(fn)
-        return fn
-
-    def _fileName(self, ob):
-        """ another variant, doesn't preserve human-readable path,
-        but otherwise makes life much easier"""
+        """ Compute a filename based on an MD5 hash: doesn't preserve
+        human-readable path, but otherwise makes life much easier """
         phys_path = '/'.join(ob.getPhysicalPath())[1:]
         hashed = md5.new(phys_path).hexdigest()
         fn = os.path.join(self._dir, hashed[:2], hashed)
@@ -76,7 +58,7 @@
         """ Gets a cache entry """
         f_path = self._fileName(ob)
         try:
-            f = open(f_path, 'rb')
+            f = filestream_iterator(f_path, 'rb')
         except IOError:
             # couldn't get the actual cache
             zLOG.LOG('FileCacheManager', zLOG.INFO,
@@ -84,38 +66,21 @@
                      '/'.join(ob.getPhysicalPath())
                      )
             return default
-        return file_producer(f)
+        return f
 
-    def ZCache_set(self, ob, data=fcplaceholder, view_name='', keywords=None,
+    def ZCache_set(self, ob, data=None, view_name='', keywords=None,
                    mtime_func=None):
         """ Sets a cache entry.
         Code swiped from FSCacheManager.
 
         XXX locks?"""
-        fn = self._fileName(ob)
+        fnId = self._fileName(ob)
 
-        if data is fcplaceholder:
+        if data is None:
             # maybe it's a File or an Image, grab the data
             data = ob.data
 
-        # the dir to the file
-        if getattr(aq_base(ob), 'isPrincipiaFolderish', 0):
-                # it's a folder, so we'll make it a folder
-                fnId = None
-                fnDr = fn
-
-        else: 
-                # it's not a folder so split it
-                fnId = fn
-                fnDr = path.dirname(fn)
-
         try:
-            try:
-                #if not path.exists(fnDr): # XXX race?
-                os.makedirs(fnDr)
-            except OSError:
-                pass
-
             if fnId:
                 # use a temp. file for writing.
                 fd, tempname = tempfile.mkstemp() #open(fnId, 'wb')
@@ -179,9 +144,6 @@
             'max_age': 3600,
             }
         self.__cacheid = '%s_%f' % (id(self), time.time())
-
-
-        
                 
     
     def ZCacheManager_getCache(self):




More information about the Zope-CVS mailing list