diff options
-rw-r--r-- | patchtracker/CacheObject.py | 63 | ||||
-rwxr-xr-x | patchtracker/ReqHandler.py | 15 |
2 files changed, 1 insertions, 77 deletions
diff --git a/patchtracker/CacheObject.py b/patchtracker/CacheObject.py deleted file mode 100644 index c37c3b5..0000000 --- a/patchtracker/CacheObject.py +++ /dev/null @@ -1,63 +0,0 @@ -import errno -import gzip -import md5 -import os - -import Conf - -class CacheMissException (Exception): - pass - -class CacheObject: - """ A CacheObject is a compressed on-disk version of a serialized object. - """ - def __init__ (self, key=None, keys=None): - self.obj = None - #print "CacheObject: key=%s keys=%s"%(key, keys) - if not key and not keys: - raise "CacheObject needs at least one of key, keys" - checksum = md5.md5() - if key: - checksum.update(key) - if keys: - for k in keys: - checksum.update(str(k)) - self.path = os.path.sep.join([Conf.cachedir, checksum.hexdigest()]) - - def get(self): - if not self.obj: - try: - if Conf.cachecompress: - self.obj = gzip.GzipFile(self.path).read() - else: - self.obj = file(self.path).read() - except IOError, e: - if e.errno != errno.ENOENT: - raise e - else: - #print "CacheObject: cache miss" - raise CacheMissException("Object not present in cache") - #print "CacheObject: cache hit" - return self.obj - - def put(self, obj): - self.obj = obj - #print "CacheObject: cache put" - try: - if Conf.cachecompress: - gzip.GzipFile(self.path, "wb").write(str(self.obj)) - else: - file(self.path, "wb").write(str(self.obj)) - except Exception, e: - os.unlink(self.path) - raise e - -if __name__ == '__main__': - co = CacheObject( key="magic" ) - try: - print "going to try to read an object before it exists" - print "first line:", co.get().split()[0] - except CacheMissException: - print "file was missing as expected. now let's try to put it and fetch it" - co.put(file("/etc/passwd").read()) - print "first line:", co.get().split()[0] diff --git a/patchtracker/ReqHandler.py b/patchtracker/ReqHandler.py index 844e108..d978953 100755 --- a/patchtracker/ReqHandler.py +++ b/patchtracker/ReqHandler.py @@ -6,7 +6,6 @@ import sys import patchtracker.Conf as Conf from patchtracker.Templates import ErrorTemplate, LetterTocTemplate, FrontPageTemplate, SearchResultsTemplate -from patchtracker.CacheObject import CacheObject, CacheMissException import patchtracker.DB as DB from patchtracker.DB import PatchTrackerDB import patchtracker.SourceArchive as SourceArchive @@ -80,12 +79,10 @@ class CmdHandler: def __init__(self, env): self.headers = [] 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 == "index": self.cmd = IndexCmd(args[1:]) elif cmdarg == "jump": @@ -98,22 +95,12 @@ 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: - if self.cacheobj: - result = self.cacheobj.get() - else: - result = self.cmd.output() - except CacheMissException: - result = self.cmd.output() - self.cacheobj.put(result) + result = self.cmd.output() return result |