cachex

package
v0.0.0-...-4675295 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: Apache-2.0 Imports: 3 Imported by: 1

README

ezcache

带超时的kv缓存库

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

func NewCache

func NewCache() *Cache

func NewCacheSyncNoExpire

func NewCacheSyncNoExpire() *Cache

func (*Cache) Delete

func (c *Cache) Delete(key string)

func (*Cache) Dispose

func (c *Cache) Dispose()

func (*Cache) Expire

func (c *Cache) Expire(key string, duration time.Duration, handler func(key string, data interface{}))

由于采用了标记的方式清楚expire, 所以可能会出现一种情况: 清理后, list中残留了一个键为[key]的expiredItem, 但后面只再次Set了[key]的值, 但没有Expire, 会导致expiredItem仍然生效 因此, 使用的时候需要注意这点

func (*Cache) Get

func (c *Cache) Get(key string) (val interface{}, ok bool)

func (*Cache) GetOrNew

func (c *Cache) GetOrNew(key string, has func(ival interface{}), create func() interface{}) interface{}

从cache中获取对象, 如果存在, 通过has方法进行处理; 如果不存在, 通过create方法创建, 接着调用has方法 该方法没有返回值

func (*Cache) Set

func (c *Cache) Set(key string, val interface{})

func (*Cache) SetExpiredSpace

func (c *Cache) SetExpiredSpace(t time.Duration)

type Context

type Context struct {
	context.Context
	// contains filtered or unexported fields
}

func NewContext

func NewContext(ctx context.Context) *Context

func (*Context) GetCache

func (ctx *Context) GetCache() *Cache

func (*Context) GetCacheGlobal

func (ctx *Context) GetCacheGlobal() *Cache

type ICache

type ICache interface {
	Set(key string, val interface{})
	Delete(key string)
	Expire(key string, duration time.Duration, handler func(key string, data interface{}))
	Get(key string) (val interface{}, ok bool)
	Dispose()
}

type IContext

type IContext interface {
	context.Context

	GetCache() *Cache
	GetCacheGlobal() *Cache
}

type IContextRequest

type IContextRequest interface {
	IContext

	GetCacheRequest() *Cache
}

type RequestContext

type RequestContext struct {
	Context
	// contains filtered or unexported fields
}

func NewRequestContext

func NewRequestContext(ctx context.Context) (r *RequestContext)

func NewRequestContextDefault

func NewRequestContextDefault() (r *RequestContext)

func (*RequestContext) GetCacheRequest

func (ctx *RequestContext) GetCacheRequest() *Cache

Jump to

Keyboard shortcuts

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