summaryrefslogtreecommitdiff
path: root/patchtracker/ReqHandler.py
diff options
context:
space:
mode:
authorSean Finney <seanius@debian.org>2009-08-31 23:10:43 +0200
committerSean Finney <seanius@debian.org>2009-09-01 08:58:00 +0200
commitf28a60d7373b5d23599c111ff18d69a94ae69a36 (patch)
tree1dec1acfe10c29d1079830e33b66180795de0064 /patchtracker/ReqHandler.py
parentad817fd1bd8d88b242fea45ea1d96315d48c3a47 (diff)
downloadpatch-tracker-f28a60d7373b5d23599c111ff18d69a94ae69a36.tar.gz
initial implementation of selective output caching
the PackageCmd and PatchCmd classes are now cached on their first request. note that this is incomplete, as the PackageCmd is also currently used to print non-static information as well (when a package name doesn't find an exact match and it does a query).
Diffstat (limited to 'patchtracker/ReqHandler.py')
-rwxr-xr-xpatchtracker/ReqHandler.py28
1 files changed, 26 insertions, 2 deletions
diff --git a/patchtracker/ReqHandler.py b/patchtracker/ReqHandler.py
index a87fd68..59e0f53 100755
--- a/patchtracker/ReqHandler.py
+++ b/patchtracker/ReqHandler.py
@@ -7,6 +7,7 @@ import sys
import patchtracker.Conf as Conf
from patchtracker.Templates import ErrorTemplate, PatchTemplate, PackageVersTemplate, LetterTocTemplate, FrontPageTemplate, SearchResultsTemplate
from patchtracker.DiffGzHandler import DiffGzHandler, DiffGzException
+from patchtracker.CacheObject import CacheObject, CacheMissException
import patchtracker.DB as DB
from patchtracker.DB import PatchTrackerDB
import pygments
@@ -158,14 +159,19 @@ class FrontPageCmd(Cmd):
class CmdHandler:
def __init__(self, env):
self.headers = []
- uri=Conf.root_url+env['PATH_INFO']
+ uri = Conf.root_url+env['PATH_INFO']
+ self.cacheobj = None
+ #print "Accept:",env['HTTP_ACCEPT']
args = uri[len(Conf.root_url)+1:].split("/")
cmdarg = args[0]
+ cacheable = False
if cmdarg == "patch":
self.cmd = PatchCmd(args[1:])
+ cacheable = True
elif cmdarg == "package":
self.cmd = PackageCmd(args[1:])
+ cacheable = True
elif cmdarg == "index":
self.cmd = IndexCmd(args[1:])
elif cmdarg == "jump":
@@ -178,11 +184,29 @@ class CmdHandler:
else:
self.cmd = ErrorCmd("invalid command/location '%s'"%(cmdarg), "404 Not found")
+ if Conf.caching and cacheable:
+ self.cacheobj = CacheObject(key=uri)
+
self.headers.append( ('Content-type', self.cmd.content_type) )
self.status = self.cmd.status
def output(self):
+ result = None
try:
- return self.cmd.output()
+ if self.cacheobj:
+ result = self.cacheobj.get()
+ else:
+ result = self.cmd.output()
+ except CacheMissException:
+ result = self.cmd.output()
+ self.cacheobj.put(result)
except DiffGzException, e:
return ErrorCmd(str(e), "500 Oh Noez!!1!").output()
+
+ return result
+
+if __name__ == '__main__':
+ fake_env = { 'PATH_INFO': sys.argv[1] }
+ cmdh = CmdHandler(fake_env)
+ print "Status: %s\nHeaders: %s"%(cmdh.status, cmdh.headers)
+ print cmdh.output()