cache

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package cache provide a Cache interface and some implement engine Usage:

import(

"github.com/beego/beego/v2/client/cache"

)

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")

 more docs http://beego.vip/docs/module/cache.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateOldToNewAdapter

func CreateOldToNewAdapter(old Cache) cache.Cache

func GetBool

func GetBool(v interface{}) bool

GetBool convert interface to bool.

func GetFloat64

func GetFloat64(v interface{}) float64

GetFloat64 convert interface to float64.

func GetInt

func GetInt(v interface{}) int

GetInt convert interface to int.

func GetInt64

func GetInt64(v interface{}) int64

GetInt64 convert interface to int64.

func GetString

func GetString(v interface{}) string

GetString convert interface to string.

func Register

func Register(name string, adapter Instance)

Register makes a cache adapter available by the adapter name. If Register is called twice with the same name or if driver is nil, it panics.

Types

type Cache

type Cache interface {
	// Get will get cached value by key.
	Get(key string) interface{}
	// GetMulti is a batch version of Get.
	GetMulti(keys []string) []interface{}
	// Put will set cached value with key and expire time.
	Put(key string, val interface{}, timeout time.Duration) error
	// Delete will delete cached value by key.
	Delete(key string) error
	// Incr will increase cached int value by key, as a counter.
	Incr(key string) error
	// Decr will decrease cached int value by key, as a counter.
	Decr(key string) error
	// IsExist can check if cached value exists or not.
	IsExist(key string) bool
	// ClearAll will clear all cache.
	ClearAll() error
	// StartAndGC will start gc routine based on config string settings.
	StartAndGC(config string) error
}

Cache interface contains all behaviors for cache adapter. usage:

cache.Register("file",cache.NewFileCache) // this operation is run in init method of file.go.
c,err := cache.NewCache("file","{....}")
c.Put("key",value, 3600 * time.Second)
v := c.Get("key")

c.Incr("counter")  // now is 1
c.Incr("counter")  // now is 2
count := c.Get("counter").(int)

func CreateNewToOldCacheAdapter

func CreateNewToOldCacheAdapter(delegate cache.Cache) Cache

func NewCache

func NewCache(adapterName, config string) (adapter Cache, err error)

NewCache Create a new cache driver by adapter name and config string. config need to be correct JSON as string: {"interval":360}. it will start gc automatically.

func NewFileCache

func NewFileCache() Cache

NewFileCache Create new file cache with no config. the level and expiry need set in method StartAndGC as config string.

func NewMemoryCache

func NewMemoryCache() Cache

NewMemoryCache returns a new MemoryCache.

type Instance

type Instance func() Cache

Instance is a function create a new Cache Instance

Directories

Path Synopsis
Package memcache for cache provider
Package memcache for cache provider
Package redis for cache provider
Package redis for cache provider

Jump to

Keyboard shortcuts

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