[storm] why weakrefdict for cache?

Gustavo Niemeyer gustavo at niemeyer.net
Fri Aug 31 15:46:57 BST 2007


Hey Bernd!

Good to see you around.  Was just talking about the memorable
sprint you guys have had with Sidnei da Silva. :-)

> imho the memory consumption problem could be handled with explicit
> deallocation of objects

You can't deallocate the object explicitly if there is a strong
reference being held in a cache dictionary.

In any case, I understand the points of both of you. I think the
bottom line is that we can't simply use a strong reference
dictionary, and a cache implementation which holds objects only
while there are other references may be suboptimal in some
cases.

The solution for both issues is simple: we need a slightly smarter
cache implementations which is able to hold, say, the N last used
objects. This is easy to implement and integrate, and is likely
to be added in the near future.


> that's a god point ... even though i am not sure in which use-case one
> should store an object in memory which may magically change its values
> without getting the object from a specific place again explicitly

As an example, the following will fail, even though it must work,
otherwise whenever a transaction is committed all the references
to objects alive are lost.

person = store.get(Person, 1)
person.name = "Bob"
store.commit()
assert store.get(Person, 1) is person

-- 
Gustavo Niemeyer
http://niemeyer.net



More information about the storm mailing list