priestc / giotto

Python web development simplified
BSD 2-Clause "Simplified" License
59 stars 10 forks source link

Add cache support #7

Closed priestc closed 11 years ago

priestc commented 11 years ago

There should be an attribute on the program class that specifies a cache time. This cache time acts as a shortcut between the model and the view. There also needs to be a Cache object that the concrete controller defines that get passed on to each controller class.

class Multiply(GiottoProgram):
    name = 'multiply
    controllers = ('http-get', 'cmd')
    model = [multiply]
    cache = 3600 # one hour
    view = [MultiplyViewer]

and the Cache class should look like this:

class Memcache(GiottoCache):
    """
    implements a `set` and `get` method for getting stuff out of the cache
    """

The cache uses three things to create the key: controller data, program name, and output mimetype. An example cache key looks like the following:

"{x: 4, y: 5}(multiply)(text/html)" "{x: 6, y: 2}(multiply)(text/plain)"