Documentation ¶
Overview ¶
Package gocache is a memory cache driver implement. base on the package: github.com/patrickmn/go-cache
Usage:
import "github.com/gookit/cache" cache.Register(gocache.NewGoCache(0, cache.FiveMinutes)) // use // cache.Set("key", "value")
Example ¶
package main import ( "fmt" "time" "github.com/gookit/cache" "github.com/gookit/cache/gocache" ) func main() { c := gocache.New() key := "name" // set c.Set(key, "cache value", cache.Seconds2) fmt.Println(c.Has(key)) // get val := c.Get(key) fmt.Println(val) time.Sleep(2 * time.Second) // get expired val2 := c.Get(key) fmt.Println(val2) // del c.Del(key) fmt.Println(c.Has(key)) }
Output: true cache value <nil> false
Index ¶
- Constants
- type GoCache
- func (g *GoCache) Clear() error
- func (g *GoCache) Close() error
- func (g *GoCache) Db() *goc.Cache
- func (g GoCache) Del(key string) error
- func (g *GoCache) DelMulti(keys []string) error
- func (g *GoCache) Get(key string) interface{}
- func (g *GoCache) GetMulti(keys []string) map[string]interface{}
- func (g *GoCache) Has(key string) bool
- func (g *GoCache) Set(key string, val interface{}, ttl time.Duration) error
- func (g GoCache) SetMulti(values map[string]interface{}, ttl time.Duration) error
Examples ¶
Constants ¶
View Source
const Name = "gocache"
Name driver name
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GoCache ¶
type GoCache struct {
// contains filtered or unexported fields
}
GoCache struct
Example (In_cachePkg) ¶
package main import ( "fmt" "time" "github.com/gookit/cache" "github.com/gookit/cache/gocache" ) func main() { c1 := gocache.NewGoCache(cache.OneDay, cache.FiveMinutes) cache.Register(gocache.Name, c1) defer cache.UnregisterAll() key := "name1" // set cache.Set(key, "cache value", cache.Seconds2) fmt.Println(cache.Has(key)) // get val := cache.Get(key) fmt.Println(val) time.Sleep(2 * time.Second) // get expired val2 := cache.Get(key) fmt.Println(val2) // del cache.Del(key) fmt.Println(cache.Has(key)) }
Output: true cache value <nil> false
func NewGoCache ¶
NewGoCache create instance with settings
Click to show internal directories.
Click to hide internal directories.