gcache

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2022 License: MIT Imports: 2 Imported by: 1

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

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 New

func New(size int) *GCache

New create an instance

func NewWithType added in v0.2.0

func NewWithType(size int, tp string) *GCache

NewWithType create an instance with cache type

func (*GCache) Clear added in v0.2.0

func (g *GCache) Clear() error

Clear all caches

func (*GCache) Close added in v0.2.0

func (g *GCache) Close() error

Close connection

func (*GCache) Db added in v0.2.0

func (g *GCache) Db() gcache.Cache

Db get the gcache.Cache

func (*GCache) Del added in v0.2.0

func (g *GCache) Del(key string) error

Del cache by key

func (*GCache) DelMulti added in v0.2.0

func (g *GCache) DelMulti(keys []string) error

DelMulti cache by keys

func (*GCache) Get added in v0.2.0

func (g *GCache) Get(key string) interface{}

Get cache by key

func (*GCache) GetMulti added in v0.2.0

func (g *GCache) GetMulti(keys []string) map[string]interface{}

GetMulti cache by keys

func (*GCache) Has added in v0.2.0

func (g *GCache) Has(key string) bool

Has cache key

func (*GCache) Set added in v0.2.0

func (g *GCache) Set(key string, val interface{}, ttl time.Duration) (err error)

Set cache by key

func (*GCache) SetMulti added in v0.2.0

func (g *GCache) SetMulti(values map[string]interface{}, ttl time.Duration) (err error)

SetMulti cache by keys

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL