Commit 8bfef678 authored by Jason Madden's avatar Jason Madden

The Python version of PickleCache.minimize does what the C version does and...

The Python version of PickleCache.minimize does what the C version does and ghosts the evicted objects.
parent 270394f3
......@@ -293,6 +293,9 @@ class PickleCache(object):
while node is not self.ring and self.non_ghost_count > target:
if node.object._p_state not in (STICKY, CHANGED):
node.prev.next, node.next.prev = node.next, node.prev
# sweeping an object out of the cache should also
# ghost it---that's what C does
node.object._p_deactivate()
node.object = None
self.non_ghost_count -= 1
node = node.next
......
......@@ -549,6 +549,22 @@ class PickleCacheTests(unittest.TestCase):
for oid in oids:
self.assertTrue(cache.get(oid) is None)
def test_minimize_turns_into_ghosts(self):
import gc
from persistent.interfaces import UPTODATE
from persistent._compat import _b
cache = self._makeOne()
oid = _b('oid_%04d' % 1)
obj = cache[oid] = self._makePersist(oid=oid, state=UPTODATE)
self.assertEqual(cache.cache_non_ghost_count, 1)
cache.minimize()
gc.collect() # banish the ghosts who are no longer in the ring
self.assertEqual(cache.cache_non_ghost_count, 0)
self.assertEqual(obj._p_state, -1)
def test_new_ghost_non_persistent_object(self):
from persistent._compat import _b
cache = self._makeOne()
......@@ -849,6 +865,8 @@ class DummyPersistent(object):
from persistent.interfaces import GHOST
self._p_state = GHOST
_p_deactivate = _p_invalidate
def _p_activate(self):
from persistent.interfaces import UPTODATE
self._p_state = UPTODATE
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment