class Blah:
def sessiontime(self):
return session.ctime
def cache_test():
import time
session.ctime = time.ctime()
b = cache.ram('blah',Blah,50)
return dict(cached=b.sessiontime(), current=session.ctime)
Because the time is not stored in the cached object, I would expect
equal 'cached' and 'current' value on every run.
But it seems that the session object is being stored together with
Blah somehow, so the values differ, starting with the second run for
the time for which the object is being held in cache:
cached : Sun Mar 28 12:22:43 2010
current : Sun Mar 28 12:23:10 2010
Is this behaviour intentional? I would expect to get fresh session
instead.
Regards :)
David
Massimo
i touched it to cache function instead of constructor:
class Blah:
def sessiontime(self):
return session.ctime
def cache_test():
import time
session.ctime = time.ctime()
def blah():
return Blah()
b = cache.ram('blah',blah,30)
return dict(cached=b.sessiontime(), current=session.ctime)
and result is the same.
David
def sestime():
return session.ctime
In controller there is:
class Blah:
def sessiontime(self):
return sestime()
def cache_test():
import time
session.ctime = time.ctime()
def blah():
return Blah()
b = cache.ram('blah',blah,30)
return dict(cached=b.sessiontime(), current=session.ctime)
And still the same, the cached and current differ. The old session is
wired into the cache somehow, hmmm..
The examples are silly, of course, just to show the problem. I wish to
use the cache to store complex objects, constructed on results of
multiple queries. The objects have various methods operating on their
properties in context of session. Once I cache the objects (to avoid
tons of queries), my program breaks :(
David
class Blah:
def sessiontime(self, session):
globals()['session'] = session
return session.ctime
def cache_test():
import time
session.ctime = time.ctime()
def blah():
return Blah()
b = cache.ram('blah',blah,30)
return dict(cached=b.sessiontime(session), current=session.ctime)
Of course, this is not a solution, just a dirty hack.
Moreover the problem is not with session object only. It seems that
whole globals at the time of storage are being attached to the object,
including request, result etc. E.g.:
class Blah2:
def req_function(self):
return request.function
def cache_test_2():
b = cache.ram('blah',Blah2,30)
return dict(function=b.req_function())
def cache_test_other():
b = cache.ram('blah',Blah2,30)
return dict(function=b.req_function())
I would anticipate that it will return the name of request function
from which it is being called,
but blah pulled from cache prints name of function from the time of
construction :-(
David
D.