[Twisted-web] caching branch
Andrea Arcangeli
andrea at cpushare.com
Thu Feb 17 23:34:28 MST 2005
On Fri, Feb 18, 2005 at 07:31:51AM +0100, Andrea Arcangeli wrote:
> And this below is the patch of caching branch from dialtone + my above
> incremental patch that speedup the rend.Page caching without changing
> the API at all, all against trunk (i.e. the code that's going online in
> a few more minutes ;).
sorry for yet another self followup but this bit from the caching branch
was missing, it was a new file and I merged into trunk using patch
instead of svn merge...
Index: nevow/cache.py
===================================================================
--- nevow/cache.py (revision 0)
+++ nevow/cache.py (revision 0)
@@ -0,0 +1,33 @@
+from time import time as now
+from nevow import inevow
+
+class SiteCache(object):
+ __implements__ = inevow.ICache,
+ _content = {}
+ def __init__(self, original):
+ self.original = original
+
+ def get(self, index, lifetime):
+ cached = self._content.get(index, None)
+ if cached is None:
+ return
+ if lifetime < 0:
+ return cached[1]
+ if cached[0] + lifetime > now():
+ return cached[1]
+
+ def set(self, toBeCached, *indexes):
+ _now = now()
+ for index in indexes:
+ self._content[index] = (_now, toBeCached)
+
+ def clear(self, what):
+ if self._content.has_key(what):
+ self._content.pop(what)
+ for key in self._content.keys():
+ if what in key:
+ self._content.pop(key)
+
+class SessionCache(SiteCache):
+ def __init__(self):
+ self._content = {}
More information about the Twisted-web
mailing list