-----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 <[email protected]> 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 <[email protected]> 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/[email protected]/msg34333.html
>>>> With regards,
>>>> David
>>>> mdipierro wrote:
>>>>>>> It depends on whether nick is a reference field.
>>>>>>> On Jan 2, 5:31 pm, Michele Comitini <[email protected]>
>>>>>>> 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 <[email protected]>:
- --
David Zejda, Open-IT cz
web development & services
http://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-----