Configuring EdgeCache – A Cache For App Engine

App Engine has a distributed caching system called EdgeCache which can be configured to quickly serve static or rarely-changed assets. To tell EdgeCache to cache your files, you need to set the following two headers:

Cache-Control: public, max-age=[time in seconds to cache]
Pragma: Public

The max-age argument takes the number of seconds to cache the given file. It must be set to at least 61 seconds.

Here’s example Java code to implement these headers. The max age is set to 86,400 seconds (1 day). The resp object represents a HttpServletResponse class:

resp.setHeader("Cache-Control", "public, max-age=86400");
resp.setHeader("Pragma", "Public");

Here’s the same code implemented in Go ( w represents http.ResponseWriter ):

w.Header().Set("Cache-Control", "public, max-age=86400")
w.Header().Set("Pragma", "Public")