# README
cache
cache is a Go cache manager. It can use many cache adapters. The repo is inspired by database/sql
.
How to install?
go get github.com/OpenStars/beego/cache
What adapters are supported?
As of now this cache support memory, Memcache and Redis.
How to use it?
First you must import it
import (
"github.com/OpenStars/beego/cache"
)
Then init a Cache (example with memory adapter)
bm, err := cache.NewCache("memory", `{"interval":60}`)
Use it like this:
bm.Put("astaxie", 1, 10 * time.Second)
bm.Get("astaxie")
bm.IsExist("astaxie")
bm.Delete("astaxie")
Memory adapter
Configure memory adapter like this:
{"interval":60}
interval means the gc time. The cache will check at each time interval, whether item has expired.
Memcache adapter
Memcache adapter use the gomemcache client.
Configure like this:
{"conn":"127.0.0.1:11211"}
Redis adapter
Redis adapter use the redigo client.
Configure like this:
{"conn":":6039"}
# Packages
Package memcache for cache provider
depend on github.com/bradfitz/gomemcache/memcache
go install github.com/bradfitz/gomemcache/memcache
Usage: import( _ "github.com/OpenStars/beego/cache/memcache" "github.com/OpenStars/beego/cache" )
bm, err := cache.NewCache("memcache", `{"conn":"127.0.0.1:11211"}`)
more docs http://beego.me/docs/module/cache.md.
Package redis for cache provider
depend on github.com/gomodule/redigo/redis
go install github.com/gomodule/redigo/redis
Usage: import( _ "github.com/OpenStars/beego/cache/redis" "github.com/OpenStars/beego/cache" )
bm, err := cache.NewCache("redis", `{"conn":"127.0.0.1:11211"}`)
more docs http://beego.me/docs/module/cache.md.
No description provided by the author
# Functions
FileGetContents Get bytes to file.
FilePutContents Put bytes to file.
GetBool convert interface to bool.
GetFloat64 convert interface to float64.
GetInt convert interface to int.
GetInt64 convert interface to int64.
GetString convert interface to string.
GobDecode Gob decodes file cache item.
GobEncode Gob encodes file cache item.
NewCache Create a new cache driver by adapter name and config string.
NewFileCache Create new file cache with no config.
NewMemoryCache returns a new MemoryCache.
Register makes a cache adapter available by the adapter name.
# Variables
1 minute.
cache file deep level if auto generated cache files.
cache expire time, default is no expire forever.
cache file suffix.
cache directory.
# Structs
FileCache is cache adapter for file storage.
FileCacheItem is basic unit of file cache adapter.
MemoryCache is Memory cache adapter.
MemoryItem store memory cache item.
# Interfaces
Cache interface contains all behaviors for cache adapter.
# Type aliases
Instance is a function create a new Cache Instance.