mycache

package
v0.0.0-...-8fa672d Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 5 Imported by: 8

Documentation

Overview

key/value 内存缓存,支持基于超时的自动无效功能

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheIFS

type CacheIFS interface {
	Destory()                                                                       // 析构
	Add(key interface{}, value interface{}, lifeSpan time.Duration) error           // 添加一个元素
	Value(key interface{}, value interface{}) error                                 // 获取一个value
	IsExist(key interface{}) bool                                                   // 判断是否存在
	Delete(key interface{}) error                                                   // 删除一个
	Clear() error                                                                   // 清空
	Close() (err error)                                                             // 关闭连接
	TryLock(key interface{}, value interface{}, lifeSpan time.Duration) (err error) //  试着加锁
	Unlock(key interface{}) (err error)                                             // 解锁
	GetKeyS(key interface{}) ([]string, error)                                      // 查询所有key
	Refresh(key interface{}, lifeSpan time.Duration) error                          // 更新时间
}

CacheIFS 缓存操作接口

type MyCache

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

MyCache 内存缓存

func NewCache

func NewCache(cachename string) (mc *MyCache)

NewCache 初始化一个cache,cachename 缓存名字

func (*MyCache) Add

func (mc *MyCache) Add(key interface{}, value interface{}, lifeSpan time.Duration) error

Add 添加一个缓存,lifeSpan:缓存时间,0表示永不超时

func (*MyCache) Clear

func (mc *MyCache) Clear() error

Clear 清空表內容

func (*MyCache) Close

func (mc *MyCache) Close() error

Close 清空表內容

func (*MyCache) Delete

func (mc *MyCache) Delete(key interface{}) error

Delete 删除一个cache

func (*MyCache) Destory

func (mc *MyCache) Destory()

Destory 添加一个缓存,lifeSpan:缓存时间,0表示永不超时

func (*MyCache) GetCache2go

func (mc *MyCache) GetCache2go() *cache2go.CacheTable

GetCache2go 获取原始cache2go操作类

func (*MyCache) GetKeyS

func (mc *MyCache) GetKeyS(key interface{}) ([]string, error)

GetKeyS 查询所有key

func (*MyCache) IsExist

func (mc *MyCache) IsExist(key interface{}) bool

IsExist 判断key是否存在

func (*MyCache) Refresh

func (mc *MyCache) Refresh(key interface{}, lifeSpan time.Duration) error

Refresh 更新时间

func (*MyCache) TryLock

func (mc *MyCache) TryLock(key interface{}, value interface{}, lifeSpan time.Duration) (err error)

TryLock 试着枷锁

func (*MyCache) Unlock

func (mc *MyCache) Unlock(key interface{}) (err error)

Unlock 试着解锁

func (*MyCache) Value

func (mc *MyCache) Value(key interface{}, value interface{}) error

Value 查找一个cache

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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