[storm] why weakrefdict for cache?
Bernd Dorn
bernd.dorn at lovelysystems.com
Fri Aug 31 11:22:02 BST 2007
Hi all
we use storm with zope (version .10) and discovered that the
store._cache attribute never caches, because the weakrefs are gone
immediatly
we changed the implementation to use a normal dict, and do a
self._cache.clear() if an invalidate(None) is issued. which is done
on commit and rollback. this makes sure there are no objects
referenced after a transaction
what about integrating this into storm?
cheers, bernd
here is the diff:
bd:~/sandbox/storm $ bzr diff storm/store.py
=== modified file 'storm/store.py'
--- storm/store.py 2007-08-15 15:41:25 +0000
+++ storm/store.py 2007-08-31 10:20:20 +0000
@@ -64,7 +64,7 @@
@param database: The L{storm.database.Database} instance to
use.
"""
self._connection = database.connect()
- self._cache = WeakValueDictionary()
+ self._cache = {} #WeakValueDictionary()
self._dirty = {}
self._order = {} # (info, info) = count
@@ -350,6 +350,8 @@
if invalidate:
for obj_info in obj_infos:
self._run_hook(obj_info, "__storm_invalidated__")
+ if obj is None:
+ self._cache.clear()
def add_flush_order(self, before, after):
"""Explicitly specify the order of flushing two objects.
More information about the storm
mailing list