Skip to content

Instantly share code, notes, and snippets.

@GoesToEleven
Created October 27, 2015 05:26
Show Gist options
  • Save GoesToEleven/fae14e351f2afcf6ef39 to your computer and use it in GitHub Desktop.
Save GoesToEleven/fae14e351f2afcf6ef39 to your computer and use it in GitHub Desktop.
Memcache for Templates in Golang
ctx := appengine.NewContext(req)
i, err := memcache.Get(ctx, "Homepage")
if err != memcache.ErrCacheMiss {
buf := bytes.NewBuffer(make([]byte))
writ := io.MultiWriter(res, buf)
tpl.ExecuteTemplate(writ, "home.html", nil)
memcache.Set(ctx, memcache.Item{
Value: buf.String(),
Key: "Homepage",
})
return
}
io.WriteString(res, i.Value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment