1
0
mirror of https://github.com/astaxie/beego.git synced 2024-12-23 15:30:50 +00:00
Beego/cache/README.md

60 lines
1.0 KiB
Markdown
Raw Normal View History

2013-04-22 10:56:30 +00:00
## cache
2013-06-20 11:58:35 +00:00
cache is a Go cache manager. It can use many cache adapters. The repo is inspired by `database/sql` .
2013-04-22 10:56:30 +00:00
2013-06-20 11:58:35 +00:00
## How to install?
2013-04-22 10:56:30 +00:00
go get github.com/astaxie/beego/cache
2013-06-20 11:58:35 +00:00
## What adapters are supported?
As of now this cache support memory, Memcache and Redis.
2013-04-22 10:56:30 +00:00
2013-06-20 11:58:35 +00:00
## How to use it?
First you must import it
2013-04-22 10:56:30 +00:00
import (
"github.com/astaxie/beego/cache"
)
2013-06-20 11:58:35 +00:00
Then init a Cache (example with memory adapter)
2013-04-22 10:56:30 +00:00
2014-08-08 04:02:44 +00:00
bm, err := cache.NewCache("memory", `{"interval":60}`)
2013-04-22 10:56:30 +00:00
2013-06-20 11:58:35 +00:00
Use it like this:
2013-04-22 10:56:30 +00:00
bm.Put("astaxie", 1, 10 * time.Second)
2013-04-22 10:56:30 +00:00
bm.Get("astaxie")
bm.IsExist("astaxie")
bm.Delete("astaxie")
2013-06-20 11:58:35 +00:00
## Memory adapter
Configure memory adapter like this:
2013-04-22 10:56:30 +00:00
{"interval":60}
2013-06-20 11:58:35 +00:00
interval means the gc time. The cache will check at each time interval, whether item has expired.
2013-04-22 10:56:30 +00:00
2013-06-20 11:58:35 +00:00
## Memcache adapter
Memcache adapter use the [gomemcache](http://github.com/bradfitz/gomemcache) client.
2013-06-20 11:58:35 +00:00
Configure like this:
2013-04-22 10:56:30 +00:00
{"conn":"127.0.0.1:11211"}
2013-06-20 11:58:35 +00:00
## Redis adapter
Redis adapter use the [redigo](http://github.com/gomodule/redigo) client.
2013-04-22 10:56:30 +00:00
2013-06-20 11:58:35 +00:00
Configure like this:
2013-04-22 10:56:30 +00:00
2013-06-20 11:58:35 +00:00
{"conn":":6039"}