Source

CherryPy Recipes / web / caching / redis_caching / __init__.py

# -*- coding: utf-8 -*-
import cherrypy

class Root(object):
    @cherrypy.expose
    def index(self):
        counter = int(cherrypy.request.cache['count'])
        counter += 1
        cherrypy.request.cache['count'] = counter
        return """<html>
<head />
<body>
    <a href="/">Hit me again</a>
    <p>Cached value: %d</p>
</body>
</html>""" % counter
    
if __name__ == '__main__':
    cherrypy.config.update({'server.socket_port': 8090})
    
    from redisplugin import RedisPlugin
    RedisPlugin(cherrypy.engine).subscribe()

    from redistool import RedisTool
    cherrypy.tools.rediscache = RedisTool()

    cherrypy.quickstart(Root(), '', {'/': {'tools.rediscache.on': True,
                                           'tools.rediscache.keys': {'count': 0}}})