在Golang中缓存数据库结果(启示)

I am currently coding a web application in Go with the help of the revel web framework. I've come to the point where I want to serve results from a database, however there's quite an amount of rows to serve (~5000-10000). The information only changes every 3 minutes, so perhaps it's a good idea to implement some form of caching.

The Revel framework offers a caching solution, however I have no idea how such a thing would work and if it's the best solution to my problem. Another solution could be to make a global array with the results and grab a slice once in a while (Would this work better if there are a lot of users? ).

Could you guys help me out? I'd really appreciate it.

In revel add

cache.memcached = true
cache.hosts="127.0.0.1:11211

To your conf/app.conf and make sure you have memcached installed. Then import github.com/revel/revel/cache and in your code you can use

var results []string
if err := cache.Get("res", &results); err == nil {
  // use results
} else {
  // do db query
  cache.Set("results", results, 3*time.Minute)
}