Cache
Middleware cache provides cache management for Macaron Instances.
Installation
go get github.com/go-macaron/cacheUsage
import (
"github.com/go-macaron/cache"
"gopkg.in/macaron.v1"
)
func main() {
m := macaron.Classic()
m.Use(cache.Cacher())
m.Get("/", func(c cache.Cache) string {
c.Put("cache", "cache middleware", 120)
return c.Get("cache")
})
m.Run()
}Options
cache.Cacher comes with a variety of configuration options(cache.Options):
Adapters
There are 8 built-in implementations of cache adapter, you have to import adapter driver explicitly except for memory and file adapters.
Following are some basic usage examples for adapters.
Memory
File
Redis
Notice Only string and int-type are allowed.
There is a special occupy mode for Redis cacher when you want to use entire database selection with large amount of cache data. By setting OccupyMode to true to enable this mode, then cacher will stop maintaining the index collection of cache data that is used to determine what data are belonging to your app, and helps you reduce CPU and memory usage in such cases.
Memcache
PostgreSQL
Use following SQL to create database:
MySQL
Use following SQL to create database:
Ledis
Nodb
Last updated
Was this helpful?