[storm] pls review strongrefcache was Re: why weakrefdict for cache?

Bernd Dorn bernd.dorn at lovelysystems.com
Tue Nov 27 16:30:14 GMT 2007


hi all!

i filed a bug https://bugs.launchpad.net/storm/+bug/172357

which has a new branch assigned, that adds support for a cache that  
holds strong references

please review

thx, bernd

On 03.09.2007, at 16:15, Gustavo Niemeyer wrote:

>
> There's a feature in Landscape which is urging my attention, so I'm
> unlikely to be able to look at this before some time next week. Here
> is an initial implementation plan, in case you want to tackle it:
>
> - Let's rename Store._cache to Store._alive.  That reflects better
>   what this attribute means.  We shouldn't have to touch the use of
>   _alive (caching will work side-by-side with the current system).
>
> - We create a cache implementation in cache.py.  It has a very
>   simple API: add(), remove(), and clear().  Store._cache will hold
>   it (let's not implement the "pluggable" aspect in the first
>   version, so that we have time to learn if our API is right).
>
> - Whenever an object is returned to the user from the Store
>   or from a ResultSet (no matter if it's loaded from database or
>   not), it's add()ed to the cache.
>
> - Internally, the cache maintains two structures: one dictionary
>   with {obj_info: obj} (this has the strongref to the obj), and
>   one list of obj_infos.  We can't have just a list of the
>   objects themselves because we don't want to touch any special
>   methods in the object implementation (e.g. __eq__).
>
> - If Cache.add() finds that obj_info is already in the dictionary,
>   it removes the object from the list, and reinserts it at the
>   start.  If the list goes above N, the last element is popped
>   from the list and the dictionary.
>
> - Store.invalidate() takes the item off the cache.  It should also
>   be taken off on _remove_from_alive (which is _remove_from_cache
>   right now, but will be renamed).
>
> - We need 100% test coverage for that, if possible using TDD.
>
>
> How does that look?

-- 
Lovely Systems, senior developer

phone: +43 5572 908060, fax: +43 5572 908060-77
Schmelzhütterstraße 26a, 6850 Dornbirn, Austria
skype: bernd.dorn






More information about the storm mailing list