[Erp5-dev] caching per object

Bartek Gorny bartek at redpoint.mn.pl
Thu Sep 14 23:28:52 CEST 2006


On 15/09/06, Jerome Perrin <jerome at nexedi.com> wrote:
> On Thu, Sep 14, 2006 at 09:04:29PM +0200, Bartek Gorny wrote:
> > Hello
> >
> > I tried to use caching methods, but it seems that a simple statement like:
> >
> >  def getWhatever(self):
> >    def cached_getWhatever():
> >      return something
> >   cached_getWhatever=CachingMethod(cached_getWhatever, id='an_id')
> >   return cached_getWhatever()
> >
> > does caching per portal type, which is very useful, but I need to do
> > caching per object - is there any way to do this?
> >
>
> This is actually does "global" caching. Cache keys are parameters you pass
> when calling the (wrapped) method.
>

Ah, got it - that's why I thought it caches per type - in my case the
wrapped method got an argument which was different for every portal
type.

BTW, is this cache system-wide, or bound to a site or user session?

> So, to make it simple, you will probably achive better performance with
> a volatile attribute:

I think you're right. Thanks for explanation!

Bartek

>  def getWhatever(self):
>    whatever = getattr(self, '_v_whatever', _MARKER)
>    if whatever is _MARKER:
>      self._v_whatever = whatever = self.computeWhatever()
>    return whatever
>
> Jerome
> _______________________________________________
> Erp5-dev mailing list
> Erp5-dev at erp5.org
> http://erp5.org/mailman/listinfo/erp5-dev
>


-- 
"Software is largely a service industry operating under the persistent
but unfounded delusion that it is a manufacturing industry."
Eric S.Raymond, "The Magic Cauldron"



More information about the Erp5-dev mailing list