def getset(self, key, obj): value = self.store.get(key) if value == None: cherrypy.log("No cache hit for %s, caching now" % key) if hasattr(obj, '__call__'): obj = obj() value = utils.dump_json(obj) self.store.set(key, value, ex=self.ttl_seconds) stats = self.store_stats(key) else: stats = self.get_stats(key) cherrypy.log("Cache hit for %s" % key) cherrypy.response.headers['x-cached-at'] = stats['cached_at'] cherrypy.response.headers['x-cache-ttl'] = stats['ttl'] return utils.load_json(value)
def GET(self, key=None): result = self.cache.getset(self.get_namespace(), self.all()) return utils.dump_json(result)
def _dumpjson(self, result): return utils.dump_json(result)