gocache

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2021 License: Apache-2.0 Imports: 4 Imported by: 1

README

gocache

Elegant and concise go cache manager, supporting multiple memories

Documentation

Index

Constants

This section is empty.

Variables

Functions

func Register

func Register(name string, store StoreInterface)

注册store

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

func New

func New(name string) (*Cache, error)

获取一个实例

func (*Cache) Clear

func (c *Cache) Clear() error

清除所有键值

func (*Cache) Delete

func (c *Cache) Delete(key string) error

删除键值

func (*Cache) Forever

func (c *Cache) Forever(key string, value interface{}) error

永久设置键值不过期

func (*Cache) Get

func (c *Cache) Get(key string) (interface{}, error)

获取键值

func (*Cache) GetStoreName

func (c *Cache) GetStoreName() string

获取store名称

func (*Cache) GetTTl added in v0.0.2

func (c *Cache) GetTTl(key string) (time.Time, error)

func (*Cache) Has

func (c *Cache) Has(key string) error

判断键是否存在

func (*Cache) Set

func (c *Cache) Set(key string, value interface{}, time int) error

设置键值以及过期时间

func (*Cache) Size added in v0.0.2

func (c *Cache) Size() int

type StoreInterface

type StoreInterface interface {
	GetStoreName() string
	// 获取缓存
	Get(key string) (interface{}, error)
	// 设置缓存带过期时间
	Set(key string, value interface{}, time int) error
	// 设置永久缓存无过期时间
	Forever(key string, value interface{}) error
	// 删除key
	Delete(key string) error
	// 判断key是否存在
	Has(key string) error
	// 全部清空
	Clear() error
	// 获取缓存key的数量
	Size() int
	// 获取expire
	GetTTl(key string) (time.Time, error)
	// 随机删除已过期key
	GC()
}

Directories

Path Synopsis
example module

Jump to

Keyboard shortcuts

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