1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-24 23:10:55 +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
bm, err := NewCache("memory", `{"interval":60}`)
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)
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
2014-01-16 16:17:43 +00:00
Memcache adapter use the vitess's [Memcache](http://code.google.com/p/vitess/go/memcache) 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/garyburd/redigo/redis) 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"}