title: Caching of (fake) static content which is actually dynamic on GAE for Python
body: <p>In my GAE app I have the following handler in app.yaml:</p>
  
  <pre><code>- url: /lang/strings.js
    script: js_lang.py
  </code></pre>
  
  <p>So a call to <code>/lang/strings.js</code> will actually map to the js_lang.py request handler which populates the response as <code>application/javascript</code>. I want this response to be cached in the browser so that the request handler only gets called once in a while (for example when I "invalidate" the cache by importing <code>/lang/strings.js?v=xxxx</code> when I deploy a new version of the app.</p>
  
  <p>For normal static content, there is the <code>default_expiration</code> element, which is very handy. And results in http response headers like this:</p>
  
  <pre><code>Expires: Fri, 01 Apr 2011 09:54:56 GMT
  Cache-Control: public, max-age=600
  </code></pre>
  
  <p>Ok, the question: is there an easy way for me to return headers such as this, without having to explicitly set them? Alternatively, is there a code snippet out there that accepts a few basic parameters such as "days" and produces the expected http-headers?</p>
  
  <p><strong>Edit 12 April 2011</strong></p>
  
  <p>I solved this very by simply setting the two headers <code>Expires</code> and <code>Cache-Control</code> like this:</p>
  
  <pre><code>import datetime
  thirty_days_in_seconds = 4320000
  expires_date = datetime.datetime.now() + datetime.timedelta(days=30)
  HTTP_HEADER_FORMAT = "%a, %d %b %Y %H:%M:00 GMT"        
  
  self.response.headers["Expires"] = expires_date.strftime(HTTP_HEADER_FORMAT)
  self.response.headers["Cache-Control"] = "public, max-age=%s" % thirty_days_in_seconds
  </code></pre>