Documentation ¶
Overview ¶
Package gcache use the github.com/bluele/gcache as cache driver
Example ¶
package main import ( "fmt" "time" "github.com/gookit/cache" "github.com/gookit/cache/gcache" ) func main() { c := gcache.New(12) 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 GCache
- func (g *GCache) Clear() error
- func (g *GCache) Close() error
- func (g *GCache) Db() gcache.Cache
- func (g *GCache) Del(key string) error
- func (g *GCache) DelMulti(keys []string) error
- func (g *GCache) Get(key string) interface{}
- func (g *GCache) GetMulti(keys []string) map[string]interface{}
- func (g *GCache) Has(key string) bool
- func (g *GCache) Set(key string, val interface{}, ttl time.Duration) (err error)
- func (g *GCache) SetMulti(values map[string]interface{}, ttl time.Duration) (err error)
Examples ¶
Constants ¶
View Source
const Name = "gcache"
Name driver name
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GCache ¶
type GCache struct {
// contains filtered or unexported fields
}
GCache driver definition
Example (In_cachePkg) ¶
package main import ( "fmt" "time" "github.com/gookit/cache" "github.com/gookit/cache/gcache" ) func main() { cache.Register(gcache.Name, gcache.New(12)) 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 NewWithType ¶ added in v0.2.0
NewWithType create an instance with cache type
Click to show internal directories.
Click to hide internal directories.