[Twisted-web] html cache with timeout
Valentino Volonghi aka Dialtone
dialtone at divmod.com
Wed Feb 2 11:35:30 MST 2005
On Wed, 2 Feb 2005 19:12:29 +0100, Andrea Arcangeli <andrea at cpushare.com> wrote:
> > t.cached(name=str(self.__class__)+IA(ctx).get('uid', ''), lifetime=10)[...]
> Isn't that going to leak memory badly with tons of users seldom
> accessing the site? At least for my usage I can't do the above or it
> would risk to run my app out of memory. lifetime isn't a timer, so
> it'll never be freed.
Since you are the one that is setting the cache this is actually not a problem at all. You can do
isLogged = IA(ctx).get('uid', None)
t.cached(name=str(self.__class__)+('1','0')[isLogged == False], lifetime=10)[..]
This won't leak anything except for logged/not logged users which is what you want.
Now it should be clear what are the advantages of being able to set the name yourself :).
> To get automatic garbage collection one should store it in the
> session, or at least attach a timer that fires indipendently if the
> rendering is enabled or not.
Just running the same thing that expires the sessions is enough. It's 5 lines of code or something like that, of course this should be left to the cache manager implementation.
> I'm using this only for the forms right now:
> def renderCachedForms(ctx, lifetime=0, *args, **kwargs):
> return tags.cached(lifetime=lifetime,
> name='formless-'+str(url.URL.fromContext(ctx)))[webform.renderForms(*args, **kwargs)]
> It's very handy to use by just repalcing webform.renderForms() with
I think you can cache the result of self.docFactory.load() in the same way you put t.cached() in loader.stan()
> I still doubt it'll be as fast as httprender cache, but I can try.
from my tests it shouldn't be that slower. But you do over 200 req/sec so it can be different.
> It has taken me minutes to enable httprender caching in the whole http
> site, so I tend to consider that API more handy, and peformance should
> be a bit higher too. So I don't see much point to use the stan cache in
> order to cache whole documents when the other lowlevel cache can be used
> in the rend.Page.
With this it should take a lot less.
More information about the Twisted-web