This is odd. I can reproduce the problem. What is even stranger is
that if I call blahstuff once the count doubles from 24 to 48 but if I
blahstuff more than once (even if with lower cache time) it does not
increase the counter more than 48.

I also tried caching a lambda:repr(Blah()) as opposed to Blah and the
problem does not occur.

Looks like when caching an instance it keep a copy in cache of the
entire environment, which includes db.

I do not understand why that happens since there is not reference from
the cache.py code to the environment nor any reference from the Blah
class.

Let' move this discussion to web2py-developers. If you are not already
there, please join.

Massimo


On Jan 4, 12:10 pm, David Zejda <d...@atlas.cz> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi :)
>
> You may check the issue even with the default simple application created
> by web admin. Simply add this to the default controller:
>
> class Blah():
>     def __init__(self):
>         pass
>
> def blahstuff():
>     p = cache.ram('blahblah',Blah,time_expire=30)
>     return dict(p=BEAUTIFY(p))
>
> def guppy():
>     from guppy import hpy
>     h = hpy()
>     label='h.heap()'
>     form = FORM(LABEL("Guppy code: "),INPUT(_name="code", _size='35',
> _value=label),INPUT(_type="submit", _value="Execute.."))
>     if form.accepts(request.vars, session):
>         heap = eval(request.vars.code)
>         label = request.vars.code
>     else:
>         heap = h.heap()
>     fullstack = h.heap().parts
>     return dict(heap=PRE(heap), fullstack=PRE(BEAUTIFY(fullstack)),
> label=label, form=form)
>
> If you visit heapy() first time, the results contains:
>
> Partition of a set of 24 objects. Total size = 80448 bytes.
>  Index  Count   %     Size   % Cumulative  % Kind (class / dict of class)
>      0     24 100    80448 100     80448 100 dict of gluon.dal.Field
>
> Once you run blahstuff(), heapy() reports:
>
> Partition of a set of 48 objects. Total size = 160896 bytes.
>  Index  Count   %     Size   % Cumulative  % Kind (class / dict of class)
>      0     48 100   160896 100    160896 100 dict of gluon.dal.Field
>
> David
>
> mdipierro wrote:
> > can you show us the guppy stats before and after caching? without
> > caching any db object?
> > can you also email me the entire app code?
>
> > On Jan 4, 9:15 am, David Zejda <d...@atlas.cz> wrote:
> > Whenever in controller/model is the class declared, the same result.
>
> > Michele Comitini wrote:
> >>>> Try to put the Blah class in the global scope of the controller.  Do
> >>>> you get same result?
>
> - --
> 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
>
> iEYEARECAAYFAk0jYp0ACgkQ3oCkkciamVEyngCfeFLsLcFyo3+97O0wc0w/cbPM
> oI8AoLY5t0URVVk2+ehOFomsMAjZzlyv
> =0hmM
> -----END PGP SIGNATURE-----

Reply via email to