On 12/10/14, Oleg Broytman <p...@phdru.name> wrote:
> Hi!
>
> On Wed, Dec 10, 2014 at 12:47:17AM +0100, "Fetchinson ."
> <fetchin...@googlemail.com> wrote:
>> 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
>
>    I hope you know that SQLObject converts _get_* and _set_* methods to
> properties so you shouldn't decorate the methods.

Sure! I really like this feature of SQLObject.

> Also most caching
> decorators are not thread-safe so you'd better implement your own
> caching with proper locking.

Well, that was exactly the question, how would I do that? :)
Precisely for the reason you mention above I was wary of using a more
or less standard caching decorator. Can't I attach the computed value
to the instance itself somehow by setting a new property?

Cheers,
Daniel


> Oleg.
> --
>      Oleg Broytman            http://phdru.name/            p...@phdru.name
>            Programmers don't die, they just GOSUB without RETURN.
>
> ------------------------------------------------------------------------------
> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
> from Actuate! Instantly Supercharge Your Business Reports and Dashboards
> with Interactivity, Sharing, Native Excel Exports, App Integration & more
> Get technology previously reserved for billion-dollar corporations, FREE
> http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
> _______________________________________________
> sqlobject-discuss mailing list
> sqlobject-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
>


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to