[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/Caching/RAMCache - RAMCache.py:1.6

Albertas Agejevas alga@codeworks.lt
Tue, 3 Dec 2002 03:45:47 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/Caching/RAMCache
In directory cvs.zope.org:/tmp/cvs-serv2460/RAMCache

Modified Files:
	RAMCache.py 
Log Message:
A fix to the RAMCache tests failing on Windows.
Made cacheIds really unique by appending a lock protected counter.


=== Zope3/lib/python/Zope/App/Caching/RAMCache/RAMCache.py 1.5 => 1.6 ===
--- Zope3/lib/python/Zope/App/Caching/RAMCache/RAMCache.py:1.5	Mon Dec  2 15:03:46 2002
+++ Zope3/lib/python/Zope/App/Caching/RAMCache/RAMCache.py	Tue Dec  3 03:45:46 2002
@@ -29,6 +29,10 @@
 # A writelock for caches dictionary
 writelock = allocate_lock()
 
+# A counter for cache ids and its lock
+cache_id_counter = 0
+cache_id_writelock = allocate_lock()
+
 class RAMCache(Persistent):
     """RAM Cache
 
@@ -50,7 +54,15 @@
     __implements__ = IRAMCache
 
     def __init__(self):
-        self._cacheId = "%s_%f" % (id(self), time())
+        global cache_id_counter
+        cache_id_nr = 0
+        cache_id_writelock.acquire()
+        try:
+            cache_id_counter +=1
+            cache_id_nr = cache_id_counter
+        finally:
+            cache_id_writelock.release()
+        self._cacheId = "%s_%f_%d" % (id(self), time(), cache_id_nr)
         self.requestVars = ()
         self.maxEntries = 1000
         self.maxAge = 3600