GAE: enable edge cache using webapp2 (Python)

This new YouTube video demonstrated the power of EdgeCaching in the GAE architecture, and in this particular paragraph of the video they demonstrate how easy it is to use leverage: http://www.youtube.com/watch?v=QJp6hmASstQ#t=11m12

Unfortunately, this is not so simple ...

I am looking to enable edge caching using the webapp2 infrastructure provided by Google.

I'm calling:

self.response.pragma = 'Public' self.response.cache_expires(300) 

but it seems to be redefined by something else.

The title I get is:

 HTTP/1.1 200 OK Pragma: Public Cache-Control: max-age=300, no-cache Expires: Sat, 23 Feb 2013 19:15:11 GMT Content-Type: application/json; charset=utf-8 Content-Encoding: gzip X-AppEngine-Estimated-CPM-US-Dollars: $0.000085 X-AppEngine-Resource-Usage: ms=39 cpu_ms=64 Date: Sat, 23 Feb 2013 19:10:11 GMT Pragma: no-cache Expires: Fri, 01 Jan 1990 00:00:00 GMT Cache-Control: no-cache, must-revalidate Vary: Accept-Encoding Server: Google Frontend Content-Length: 600 

I use top level ndb:

 app = ndb.toplevel(webapp2.WSGIApplication(... 

I tried the technique described here, but they don't seem to apply to webapp2: http://code.google.com/p/googleappengine/issues/detail?id=2258#c14

I also looked at this post: https://groups.google.com/d/topic/webapp2/NmHXoZZSVvo/discussion

I tried to install everything manually without success. Something overrides the cache settings.

Is there any way to make it work with webapp2? Any other option is welcome.

EDIT: I am using the URL with the version prefix: http://version.appname.appspot.com , and this is probably the cause of my problem.

+4
source share
3 answers

That should be all you need:

 self.response.cache_control = 'public' self.response.cache_control.max_age = 300 
+6
source

Check Caching Details for more information. You may have broken some rules. The next best part:

The response can only be stored in cloud CDN caches if the following is true:

  • It was served by a backend service with caching enabled.
  • This is a response to a GET request.
  • Status code: 200, 203, 300, 301, 302, 307 or 410.
  • It has a Cache-Control: public directive.
  • It has a Cache-Control: s-maxage, Cache-Control: max-age or Expires header.
  • It has either a Content-Length header or a Transfer-Encoding header.

In addition, there are checks that block response caching. The response will not be cached if one of the following statements is true:

  • It has a Set-Cookie header.
  • His body exceeds 4 MB.
  • It has a Vary header with a value other than Accept, Accept-Encoding, or - Origin.
  • It has a Cache-Control directive: no-store, no-cache or private.
  • In the corresponding request was the Cache-Control: no-store directive.
+2
source

I assume that you are mixing two related but different ideas.

The first idea that you refer to the video about is to have certain files in your application, served by a pool of App Engine servers that specialize in serving static content. This is faster than your application is serving these files, as there will be no delay in starting a new instance of your application for serving a static file. (Think hard about serving your .js and .css this way.) This static service center is fully controlled by the upload time of the application, through the ads you make in app.yaml (or appengine-web.xml for Java applications).

The second idea is to organize the HTTP headers for the pages that your application has chosen to cache with caches outside the application mechanism.

If you declare files static, you have some control over adding HTTP response headers that will be served along with the file. See the documentation for configuring static files .

+1
source

All Articles