O'Reilly logo

Go Web Development Cookbook by Arpit Aggarwal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it…

  1. Install the github.com/astaxie/beego/cache package using the go get command, as follows:
$ go get github.com/astaxie/beego/cache
  1. Move to $GOPATH/src/my-first-beego-project/controllers and create cachecontroller.go, where we will define the GetFromCache handler, which will get the value for a key from a cache and write it to an HTTP response, as follows:
package controllersimport (  "fmt"  "time"  "github.com/astaxie/beego"  "github.com/astaxie/beego/cache")type CacheController struct {  beego.Controller}var beegoCache cache.Cachevar err errorfunc init() {  beegoCache, err = cache.NewCache("memory",  `{"interval":60}`)  beegoCache.Put("foo", "bar", 100000*time.Second)}func (this *CacheController) GetFromCache() { foo := beegoCache.Get("foo") ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required