Supporting cache control for static files with cgi/server mode

"John P. Rouillard" <[email protected]>
Newsgroups gmane.comp.bug-tracking.roundup.devel
Message-ID <[email protected]>
Hi all:

I have been trying to get css, js (and other files) to be cached
client side. I usually run a front end web server (hiawatha) that
reverse proxies to the roundup-server.

I was trying to get uwsgi to serve up these files but I can't seem to
get the cache max-age and other headers to work. Also trying to serve
static files with hiawatha wasn't quite working either.

So I have been looking at what it would take to make the native
Client::serve_file (for attachments/messages) or
Client::serve_static_file (@@file/) set caching headers.

I am considering two ways to configure this:

  1) in config.ini add a new section [cache-control] with file
     extensions as keys.  So:

        [cache]
        js = public, max-age=86400
        css = public, max-age=2419200
        rss = no-cache
        * = immutable ; used for file attachments/messages

     the values are returned as the value for the cache-control
     header.  In this case, javascript files have a max-age of a day,
     can be cached and reused for all users. Css lasts for a month,
     rss files are cached, but validated and all other files
     (e.g. attachments/messages) are immutable.

     One drawback is that I would need to define all possible
     extensions since the main config.ini file format enforces a
     schema.

  2) define a new dict in the cgi/client.py::Client class:

       Cache_Control = {}

     Use interfaces.py to set the values in that dict.  Keys/values
     same as in the ini file implementation. This option also allows
     for a future enhancement by assigning a function as the
     value. The function would take the path/name of the file as an
     argument.

Also setting the expires headers could be done the same way ([expires]
or Expires = {}).  The values are expressed as a roundup interval.

Then a request for a file extracts the extension and does a lookup to
get a cache-control (preferred) or expires header. The cache-control is
used as is. The expires interval is added to the current date and
returned in proper format.

In the future, the filename (without path, with extension) can be
looked up before the extension lookup happens. This allows override
for specific files and if the file is not found it falls back to the
defaults for the file type.
    
Quips, comments, evasions, questions or answers?

--
				-- rouilj
John Rouillard
===========================================================================
My employers don't acknowledge my existence much less my opinions.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.