[Zope-Checkins] CVS: Zope/lib/python/ZODB - Connection.py:1.104

Shane Hathaway shane at zope.com
Wed Dec 10 15:02:45 EST 2003


Update of /cvs-repository/Zope/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv2631

Modified Files:
	Connection.py 
Log Message:
Improved documentation of the refresh-related functionality.

- Renamed updateCodeTimestamp() to resetCaches().

- Added a test of resetCaches().

- Removed a spurious comment about chaining connections together.


=== Zope/lib/python/ZODB/Connection.py 1.103 => 1.104 ===
--- Zope/lib/python/ZODB/Connection.py:1.103	Mon Dec  8 16:12:25 2003
+++ Zope/lib/python/ZODB/Connection.py	Wed Dec 10 15:02:15 2003
@@ -33,16 +33,20 @@
 from ZODB.serialize \
      import ObjectWriter, getClassMetadata, ConnectionObjectReader
 
-global_code_timestamp = 0
+global_reset_counter = 0
 
-def updateCodeTimestamp():
-    """Called after changes are made to persistence-based classes.
-
-    Causes all connection caches to be re-created as the connections are
-    reopened.
+def resetCaches():
+    """Causes all connection caches to be reset as connections are reopened.
+    
+    Zope's refresh feature uses this.  When you reload Python modules,
+    instances of classes continue to use the old class definitions.
+    To use the new code immediately, the refresh feature asks ZODB to
+    clear caches by calling resetCaches().  When the instances are
+    loaded by subsequent connections, they will use the new class
+    definitions.
     """
-    global global_code_timestamp
-    global_code_timestamp = time()
+    global global_reset_counter
+    global_reset_counter += 1
 
 class Connection(ExportImport, object):
     """Object managers for individual object space.
@@ -55,12 +59,9 @@
     _tmp=None
     _debug_info=()
     _opened=None
-    _code_timestamp = 0
+    _reset_counter = 0
     _transaction = None
 
-    # Experimental. Other connections can register to be closed
-    # when we close by putting something here.
-
     def __init__(self, version='', cache_size=400,
                  cache_deactivate_after=60):
         """Create a new Connection"""
@@ -76,7 +77,7 @@
             self._cache.cache_drain_resistance = 100
         self._incrgc = self.cacheGC = cache.incrgc
         self._committed = []
-        self._code_timestamp = global_code_timestamp
+        self._reset_counter = global_reset_counter
         self._load_count = 0   # Number of objects unghosted
         self._store_count = 0  # Number of objects stored
 
@@ -161,7 +162,7 @@
         self._storage = odb._storage
         self._sortKey = odb._storage.sortKey
         self.new_oid = odb._storage.new_oid
-        if self._code_timestamp != global_code_timestamp:
+        if self._reset_counter != global_reset_counter:
             # New code is in place.  Start a new cache.
             self._resetCache()
         else:
@@ -173,8 +174,11 @@
         return self
 
     def _resetCache(self):
-        """Creates a new cache, discarding the old."""
-        self._code_timestamp = global_code_timestamp
+        """Creates a new cache, discarding the old.
+
+        See the docstring for the resetCaches() function.
+        """
+        self._reset_counter = global_reset_counter
         self._invalidated.clear()
         cache_size = self._cache.cache_size
         self._cache = cache = PickleCache(self, cache_size)




More information about the Zope-Checkins mailing list