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

Jens Vagelpohl jens at dataflake.org
Sun Aug 29 14:20:55 EDT 2004


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

Modified Files:
	FileCacheManager.py 
Log Message:
- protect getting the FileCache by using thread locks - this prevents
  more than one instance getting created and used.


=== Products/FileCacheManager/FileCacheManager.py 1.15 => 1.16 ===
--- Products/FileCacheManager/FileCacheManager.py:1.15	Sat Aug 28 20:53:09 2004
+++ Products/FileCacheManager/FileCacheManager.py	Sun Aug 29 14:20:55 2004
@@ -14,6 +14,7 @@
 
 import os
 import time
+from thread import allocate_lock
 
 from AccessControl import ClassSecurityInfo
 from AccessControl.Permissions import view_management_screens
@@ -25,6 +26,7 @@
 from permissions import change_cache_managers
 
 caches = {}
+cache_lock = allocate_lock()
 
 class FileCacheManager(RAMCacheManager):
     """ A cache manager for caching data to filesystem """
@@ -61,17 +63,20 @@
         """ Cache Settings """
         cacheid = self.__cacheid
         try:
-            return caches[cacheid]
-        except KeyError:
-            cache = FileCache()
+            cache_lock.acquire()
+            try:
+                return caches[cacheid]
+            except KeyError:
+                cache = FileCache()
+                cache.setDir(self._dir)
+                cache.setTempfileDir(self._tempfile_path)
+                cache.setNamingExpression(self._naming_expr_text)
+                caches[cacheid] = cache
+
+                return cache
+        finally:
+            cache_lock.release()
 
-            cache.setDir(self._dir)
-            cache.setTempfileDir(self._tempfile_path)
-            cache.setNamingExpression(self._naming_expr_text)
-
-            caches[cacheid] = cache
-
-            return cache
 
     security.declareProtected(view_management_screens, 'getDir')
     def getDir(self):



More information about the Zope-CVS mailing list