[Zodb-checkins] SVN: ZODB/trunk/src/ZEO/ Added a method to clear the cache.
Jim Fulton
jim at zope.com
Tue Nov 18 20:45:06 EST 2008
Log message for revision 93119:
Added a method to clear the cache.
Changed:
U ZODB/trunk/src/ZEO/cache.py
U ZODB/trunk/src/ZEO/tests/test_cache.py
-=-
Modified: ZODB/trunk/src/ZEO/cache.py
===================================================================
--- ZODB/trunk/src/ZEO/cache.py 2008-11-19 01:45:03 UTC (rev 93118)
+++ ZODB/trunk/src/ZEO/cache.py 2008-11-19 01:45:05 UTC (rev 93119)
@@ -208,7 +208,7 @@
self.f.write(magic+z64)
logger.info("created temporary cache file %r", self.f.name)
- self._initfile(self.f, fsize)
+ self._initfile(fsize)
# Statistics: _n_adds, _n_added_bytes,
# _n_evicts, _n_evicted_bytes,
@@ -225,18 +225,24 @@
def fc(self):
return self
+ def clear(self):
+ self.f.seek(ZEC_HEADER_SIZE)
+ self.f.truncate()
+ self._initfile(ZEC_HEADER_SIZE)
+
##
# Scan the current contents of the cache file, calling `install`
# for each object found in the cache. This method should only
# be called once to initialize the cache from disk.
- def _initfile(self, f, fsize):
+ def _initfile(self, fsize):
maxsize = self.maxsize
+ f = self.f
read = f.read
seek = f.seek
write = f.write
seek(0)
if read(4) != magic:
- raise ValueError("unexpected magic number: %r" % _magic)
+ raise ValueError("unexpected magic number: %r" % magic)
self.tid = read(8)
if len(self.tid) != 8:
raise ValueError("cache file too small -- no tid at start")
Modified: ZODB/trunk/src/ZEO/tests/test_cache.py
===================================================================
--- ZODB/trunk/src/ZEO/tests/test_cache.py 2008-11-19 01:45:03 UTC (rev 93118)
+++ ZODB/trunk/src/ZEO/tests/test_cache.py 2008-11-19 01:45:05 UTC (rev 93119)
@@ -231,6 +231,20 @@
# VM).
del testVeryLargeCaches
del testConversionOfLargeFreeBlocks
+
+ def test_clear_zeo_cache(self):
+ cache = self.cache
+ for i in range(10):
+ cache.store(p64(i), n2, None, str(i))
+ cache.store(p64(i), n1, n2, str(i)+'old')
+ self.assertEqual(len(cache), 20)
+ self.assertEqual(cache.load(n3), ('3', n2))
+ self.assertEqual(cache.loadBefore(n3, n2), ('3old', n1, n2))
+
+ cache.clear()
+ self.assertEqual(len(cache), 0)
+ self.assertEqual(cache.load(n3), None)
+ self.assertEqual(cache.loadBefore(n3, n2), None)
def testChangingCacheSize(self):
# start with a small cache
More information about the Zodb-checkins
mailing list