Costas Malamas wrote:Also, in a related thought, have you tried redirecting self.writeln() to stuff HTML into a cache to speed up response time? does that work? it's the next step in my optimization...
each URL is a unique page - look for the rendered page in the cache. If not, render it from a cheetah template
[ ... ]
I'm using the similar approach, though a bit more sophisticated. Again, the template files are interpreted with Cheetah.
class CheetahTemplateFileCache:
"""
Caches Cheetah's template files. Note, that classes instead of instances are stored in a cache. This is
required because instances are modified by Cheetah and are not safe for
re-use and thus must be created fresh on each usage.
"""srcFileTag = re.compile('Source file: [^\n]+')
def __init__(self):
self.cache = {}
self.lock = threading.Lock()
def genTemplate(self, fileName):
t = Template(file=fileName)
temp = {}
src = t.generatedModuleCode()
src = self.srcFileTag.sub('XXX', src) # workaround Cheetah bug
exec src in temp
tklass = temp['GenTemplate']
if not tklass:
raise Error("Can't construct template for %s" % fileName)
return tklass
def addToCache(self, fileName):
tklass = self.genTemplate(fileName)
self.cache[fileName] = (tklass, time.time())
return tklass
def get(self, fileName):
"Returns a Cheetah's Template for given file name."
self.lock.acquire()
try:
tklass = None
if not self.cache.has_key(fileName):
tklass = self.addToCache(fileName)
else:
tklass, mtime = self.cache[fileName]
newmtime = os.path.getmtime(fileName)
if newmtime > mtime:
tklass = self.addToCache(fileName)
return tklass()
finally:
self.lock.release()------------------------------------------------------- This SF.net email is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just sharpen your skills. Sign up for IBM's Free Linux Tutorials. Learn everything from the bash shell to sys admin. Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click _______________________________________________ Webware-discuss mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/webware-discuss
