storing persisten object in python dictionaries
hi! i have a writeen am framework where objects have unique ids and instances are stored in btreefolders, one per class. if i want to retrieve an instance based on id, i lookup it's class name and the get the class' container path from my metadata manager (f.ex. "/app/data/Appointments/instances"). now i traverse to this container and get the object with given id from there. the process of traversing to the class' container folder is done on each object get. a cool optimization for me would be to cache class container folders in a python dictionary (much faster than traversal), but this doesn't work. the main problem is that objects retrieved from these cached folders have broken acquisition. actually i asked a similar question some time ago and was told: "don't store persistent objects in python dicts." i changed my code back to traversal and everything works, but now i finally reached the optimization stage and profiling indeed shows a huge improvement in object lookup with class container caching enabled. so can anybody tell me why this doesn't work, or what to respect to make it working? btw. the cache dict is implemented as a volatile attribute (_v_classContainerDict) of a singleton object in the db. best regards, jürgen herrmann _______________________________________________________________________
XLhost.de - eXperts in Linux hosting <<
Jürgen Herrmann Konrad Adenauer Allee 43, DE-93051 Regensburg Fon: +49 (0)700 XLHOSTDE [0700 95467833] Fax: +49 (0)721 151 463027 WEB: http://www.XLhost.de
Storing persistent object in object outside of ZODB can incur in the problem of passing object(s) between threads, and, therefore, passing one object which is related to a connection on the ZODB to another context with a different connection. Also, AFAIK, keep in mind _v_ attributes are not involved in transaction machinery of Zope. This means that if you have an error inside you transaction after you modified the _v_ cache, you will have the cache modified even tough the transaction has been aborted. Regards Marco -- Marco Bizzarri http://iliveinpisa.blogspot.com/
You don't need to traverse /me thinks. Item access is fast. How about: app.data[classId].instances[obId] Stefan On 26. Okt 2006, at 05:44, Jürgen Herrmann wrote:
i have a writeen am framework where objects have unique ids and instances are stored in btreefolders, one per class. if i want to retrieve an instance based on id, i lookup it's class name and the get the class' container path from my metadata manager (f.ex. "/app/data/Appointments/instances"). now i traverse to this container and get the object with given id from there.
-- Anything that, in happening, causes itself to happen again, happens again. --Douglas Adams
participants (3)
-
Jürgen Herrmann -
Marco Bizzarri -
Stefan H. Holek