[storm] why weakrefdict for cache?

Michael Bayer mike_mp at zzzcomputing.com
Sat Sep 1 18:59:15 BST 2007


On Aug 31, 2007, at 10:46 AM, Gustavo Niemeyer wrote:

>
> 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.

Hi -

I've been watching this thread, and I thought I'd mention that in  
SQLAlchemy, we moved from a weak-referencing identity map to a strong  
referencing one by default (with a weak-valued option) many versions  
ago.  The use case on our side for the strong-referencing map is  
someone who is making changes to multiple objects but not maintaining  
them in the local namespace; since SA's Session currently does not  
maintain a strongly referenced collection of "dirty" objects, they'd  
get garbage collected before a flush could occur. An LRU-based  
approach wouldn't fix this for us.   While we might someday reinstate  
a strongly-referenced "dirty" collection, the basic idea of a  
strongly referenced identity map is generally not a problem for our  
users; the use case where someone is looping through many objects and  
throwing away as they iterate is pretty rare and those folks either  
expunge the objects explicitly or use the "weak referencing" option  
on their session.

- mike





More information about the storm mailing list