I recently discovered that page object attributes in CherryPy are persistent between requests (and between clients). So I'm wondering, would it make sense to store page output in such an attribute? Like this:
class Page:
def default(self, pagenumber):
if pagenumber not in self.validpages:
return 'Page number not found'
try:
html = self.pageoutput[pagenumber]
except KeyError:
html = self.formatter(self.dbcall(pagenumber))
return html
default.exposed = True
def formatter(self, data):
html = # Formatting code here
return html
def dbcall(self, pagenumber):
data = # Database lookup code here
return data
I know CherryPy caches GET requests by default. In my tests, when an object attribute was part of the output and that attribute changed, CherryPy served the attribute's new value. Does that mean the output was only partially cached?
To me this would be useful as long as you updated self.pageoutput every time you changed your database. The only difficulty I could imagine is if I wanted to display user-specific information. What do you think?