diff --git a/plone/scale/storage.py b/plone/scale/storage.py index 725378b..ea18cbb 100644 --- a/plone/scale/storage.py +++ b/plone/scale/storage.py @@ -62,6 +62,7 @@ def scale(self, factory=None, **parameters): info = storage.get(key) modified = self.modified and self.modified() if info is not None and modified > info['modified']: + del storage[info['uid']] info = None # invalidate when the image was updated if info is None and factory: result = factory(**parameters) diff --git a/plone/scale/tests/test_storage.py b/plone/scale/tests/test_storage.py index 21725c8..ece76cd 100644 --- a/plone/scale/tests/test_storage.py +++ b/plone/scale/tests/test_storage.py @@ -105,6 +105,18 @@ def testDeleteRemovesItemAndIndex(self): del storage[scale['uid']] self.assertEqual(len(storage), 0) + def testCleanUpOldItems(self): + storage = self.storage + scale_old = storage.scale(factory=self.factory, foo=23, bar=42) + next_modified = storage.modified() + 1 + storage.modified = lambda: next_modified + scale_new = storage.scale(factory=self.factory, foo=23, bar=42) + self.assertEqual(len(storage), 2) + self.assertEqual(scale_new['uid'] in storage, True) + self.assertEqual(scale_old['uid'] in storage, False) + del storage[scale_new['uid']] + self.assertEqual(len(storage), 0) + def test_suite(): from unittest import defaultTestLoader