[SQLObject] caching an expensive property
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Fetchinson . <fet...@go...> - 2014-12-09 23:47:23
|
What's the best strategy for some kind of caching of an expensive property? Let's say I have the following: class obj( SQLObject ): somefield = StringCol( ) someotherfield = StringCol( ) def _get_expensivestuff( self ): # takes a long time return result And if my obj instance is alive for a long time and expensivestuff gets accessed many times I'd like to just compute result once, store it somewhere (where?) and return it from there. I'm aware of memoizing the result of a function using a suitable decorator but I'm concerned about thread safety and I'm not terribly knowledgeable about the internals of sqlobject. Any ideas would help a lot. Thanks, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown |