On 12/10/14, Oleg Broytman <p...@phdru.name> wrote:
> On Wed, Dec 10, 2014 at 01:09:50AM +0100, "Fetchinson ."
> <fetchin...@googlemail.com> wrote:
>> On 12/10/14, Oleg Broytman <p...@phdru.name> wrote:
>> > 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?
>
>    The classical approach is:
>
>     def __init__(self):
>         self.__cache = None
>         self.__cache_lock = Lock()
>
>     def _get_value(self):
>         if self.__cache is not None:
>             return self.__cache
>         self.__cache_lock.acquire()
>         try:
>             if self.__cache is not None: # Calculated in another thread
>                 return self.__cache
>             self.__cache = ...do expensive calculation once...
>             return self.__cache
>         finally: # finally works both for exceptions and returns
>             self.__cache_lock.release()

Hi Oleg, thanks again, this pushed me in the right direction and found

http://code.activestate.com/recipes/302997/

which is a pretty cool caching object including an implementation for
functions, just what I need. Now my application is a lot faster, in
some cases by a factor of 10 :)

Right now I'm happy with how things are, but I suspect that the
initial slowness was simply because I'm not very good with SQL or
SQLObject in particular and I'm not able to write the most optimal
queries. I guess I'll ask you about these things in a separate thread
:)

Thanks again,
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