Sorry. I got confused too. You say this leads to the leak:

    class Blah():
        def __init__(self):
            pass
    def blah2():
        return Blah()
    p = cache.ram('blahblah',blah2,time_expire=30)

so there is o db involved? Are you sure 'blahblah' is a constant in
your code and not a variable? Is this the exact code you are running?


On Jan 3, 5:42 pm, David Zejda <d...@atlas.cz> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hello Massimo,
>
> sorry, but I really do not understand. :-|
>
> How do I store whole record if the only thing I'm trying to store is
> instance of a dummy class? In the last example with empty __init__ there
> is no record involved at all!
>
> If I do exactly what Michele suggested:
>
> class Blah():
>     def __init__(self):
>         self.nick = db.person[1].nick
>
> def blah_f():
>     return Blah()
>
> p = cache.ram('blahblah', blah_f,time_expire=30)
>
> result is the same, of course.
>
> David
>
>
>
> mdipierro wrote:
> > This is not what Michele suggested. You are still storing the entire
> > record.
>
> > On Jan 3, 12:22 pm, David Zejda <d...@atlas.cz> wrote:
> > Dear Massimo,
>
> > thank you for the reply, but Michele's advice makes no difference.
>
> > I just noticed that even this one leads to "the leak":
>
> >     class Blah():
> >         def __init__(self):
> >             pass
>
> >     def blah2():
> >         return Blah()
>
> >     p = cache.ram('blahblah',blah2,time_expire=30)
>
> > Since I avoid storing objects of classes declared in model or
> > controllers I do not have problems. But still I do not understand why
> > when I store such object in cache, whole copy of db model goes into
> > memory. IMO if there is no solution for the behaviour, at least the
> > danger should be emphasized in cache docs, because I doubt that anybody
> > would anticipate it.
>
> > Wising you a nice day!
> > David
>
> > mdipierro wrote:
> >>>> yes but you are not following Michele's advice. If you cache a record
> >>>> or a an object like a reference, you are storing in ram of copy db
> >>>> (the leak). You should cache values or dictionaries. As long as those
> >>>> values are not reference fields there should be no leaks.
> >>>> I am not sure the term leak is appropriate here. When you cache you
> >>>> store something and storage takes space, until you clear cache. The
> >>>> bigger the object you cache, the more space it takes.
> >>>> On Jan 3, 4:21 am, David Zejda <d...@atlas.cz> wrote:
> >>>> Hi,
> >>>> nick is not reference field. To make it sure that the issue is not
> >>>> dependent on the field definition I checked it with as simple Field as
> >>>> possible:
> >>>> Field('trustworthiness', 'double', default=0),
> >>>> defined in my model and added conversion to str:
> >>>>     class Blah():
> >>>>         def __init__(self):
> >>>>             self.nick = str(db.person[1].trustworthiness)
> >>>>     p = cache.ram('blahblah',Blah,time_expire=30)
> >>>> Also,
> >>>> def blah_f():
> >>>>      return Blah()
> >>>> makes no change, leads to the same leak.
> >>>> The leak appears regardless to the place of the declaration of Blah
> >>>> class. I tried to declare it in top level of model, in controller, and
> >>>> inside function of controller, no difference.
> >>>> It is possible that this IMO weird behaviour is related to another issue
> >>>> which teased me months ago:
> >>>>http://www.mail-archive.com/web2py@googlegroups.com/msg34333.html
> >>>> With regards,
> >>>> David
> >>>> mdipierro wrote:
> >>>>>>> It depends on whether nick is a reference field.
> >>>>>>> On Jan 2, 5:31 pm, Michele Comitini <michele.comit...@gmail.com>
> >>>>>>> wrote:
> >>>>>>>> what if you do this?
> >>>>>>>> class Blah():
> >>>>>>>>     def __init__(self):
> >>>>>>>>         self.nick = db.person[1].nick
> >>>>>>>> def blah_f():
> >>>>>>>>     return Blah()
> >>>>>>>>  p = cache.ram('blahblah', blah_f,time_expire=30)
> >>>>>>>> 2011/1/2 David Zejda <d...@atlas.cz>:
>
> - --
> David Zejda, Open-IT cz
> web development & serviceshttp://www.o-it.info
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
> Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org
>
> iEYEARECAAYFAk0iXskACgkQ3oCkkciamVHYZgCdFltRuwqLh1y3NPmS45VxNfnh
> 9iUAniwUeoXlSbtCniEnc99Q0sKzIm9+
> =SRTR
> -----END PGP SIGNATURE-----

Reply via email to