2

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.

serenesat
  • 4,611
  • 10
  • 37
  • 53
NLScotty
  • 96
  • 1
  • 9
  • 2
    Have you read the [doc](http://revel.github.io/manual/cache.html) ? Read from cache first, if no cache, read from db, then set cache. If update, update cache, too. – holys Apr 22 '15 at 11:46
  • 1
    You can use `redis` or `memcached`. [example](https://github.com/huacnlee/mediom/blob/master/conf/app.conf#L29) – holys Apr 22 '15 at 11:48
  • Could you try EnableCache? It's a cache lib currently used in an Brazilian e-commerce system by my team. I recently put the implementation at GitHub. I hope to help you! Let me know whether this is lib fit to your scenario. https://github.com/darciopacifico/enablecache – DLopes Oct 29 '15 at 13:21

1 Answers1

1

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)
}
LenW
  • 3,054
  • 1
  • 24
  • 25