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

Albertas Agejevas alga@codeworks.lt
Tue, 3 Dec 2002 09:43:57 -0500


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

Modified Files:
	RAMCache.py 
Log Message:
Added a comment on cache id generation.
Refactored the code a bit.


=== Zope3/lib/python/Zope/App/Caching/RAMCache/RAMCache.py 1.6 => 1.7 ===
--- Zope3/lib/python/Zope/App/Caching/RAMCache/RAMCache.py:1.6	Tue Dec  3 03:45:46 2002
+++ Zope3/lib/python/Zope/App/Caching/RAMCache/RAMCache.py	Tue Dec  3 09:43:57 2002
@@ -54,15 +54,21 @@
     __implements__ = IRAMCache
 
     def __init__(self):
-        global cache_id_counter
-        cache_id_nr = 0
+
+        # A timestamp and a counter are used here because using just a
+        # timestamp and an id (address) produced unit test failures on
+        # Windows (where ticks are 55ms long).  If we want to use just
+        # the counter, we need to make it persistent, because the
+        # RAMCaches are persistent.
+
         cache_id_writelock.acquire()
         try:
+            global cache_id_counter
             cache_id_counter +=1
-            cache_id_nr = cache_id_counter
+            self._cacheId = "%s_%f_%d" % (id(self), time(), 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