[Twisted-web] Static.File and browser caching

Ed Suominen general at eepatents.com
Thu Mar 31 15:14:34 MST 2005


This was suggested by "jerub" on #twisted.web for Nevow usage.  Maybe 
you'll find it helpful for figuring out how to deal with the caching 
issue with twisted.web as well.

Best regards, Ed


class StaticData(static.Data):
    """
    I am an override to Nevow's static.Data class to render static
    objects with the time they were created. Hopefully won't be
    necessary with a newer release of Nevow
    
    """
    def __init__(self, *arg, **kw):
        self.createTime = time.time()
        static.Data.__init__(self, *arg, **kw)

    def renderHTTP(self, ctx):
        request = IRequest(ctx)
        request.setLastModified(self.createTime)
        return static.Data.renderHTTP(self, ctx)


On Thursday 31 March 2005 01:47 pm, Matt Feifarek wrote:
> Hello.
>
> Static.File doesn't seem to support any of the cache features that
> modern browsers use.
>
> There are various HTTP headers that govern this, including Etag,
> Cache-Control, Expires, etc. The Twisted server returns a
> comparatively minimal set of headers (hit twistedmatrix.com and look
> at the headers).
>
> Also, as far as I can tell, a "good citizen" HTTPD changes the
> response from a "200" to another response code that indicates
> "nothing new here", under certain circumstances. OR, it lets the
> browser figure that out... but it has to give the browser enough
> headers for it to do so.
>
> Is there a subclass of Static.File somewhere in Twisted that supports
> these features, or am I perhaps looking in the wrong place for this
> functionality?
>



More information about the Twisted-web mailing list