cache

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseCache

func CloseCache()

Types

type Cache

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

type DiskCache

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

func (*DiskCache) Add

func (d *DiskCache) Add(key any, value any, lifeSpan time.Duration)

func (*DiskCache) Clear

func (d *DiskCache) Clear() bool

func (*DiskCache) Close

func (d *DiskCache) Close()

func (*DiskCache) Delete

func (d *DiskCache) Delete(key any)

func (*DiskCache) Get

func (d *DiskCache) Get(key any) (any, bool)

func (*DiskCache) IsExist

func (d *DiskCache) IsExist(key any) bool

func (*DiskCache) Range

func (d *DiskCache) Range(f func(key, value any) bool)

func (*DiskCache) Set

func (d *DiskCache) Set(key any, value any, duration time.Duration)

func (*DiskCache) Value

func (d *DiskCache) Value(key any) (any, bool)

type ICache

type ICache interface {
	Add(key any, value any, lifeSpan time.Duration)
	Value(key any) (any, bool)
	IsExist(key any) bool
	Clear() bool
	Get(key any) (any, bool)
	Set(key any, value any, duration time.Duration)
	Range(f func(key, value any) bool)
	Delete(key any)
	Close()
}

func OnDiskCache

func OnDiskCache(cachePath string) ICache

func OnGetCache

func OnGetCache(cachename string, persistent ...bool) ICache

OnGetCache 初始化一个cache cachename 缓存名字

func OnMemCache

func OnMemCache(cachename string) ICache

type MemCache

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

func New

func New(cleaningInterval time.Duration) *MemCache

New creates a new cache that asynchronously cleans expired entries after the given time passes.

func (*MemCache) Add

func (c *MemCache) Add(key any, value any, lifeSpan time.Duration)

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

func (*MemCache) Clear

func (c *MemCache) Clear() bool

Clear 清空表內容

func (*MemCache) Close

func (cache *MemCache) Close()

Close closes the cache and frees up resources.

func (*MemCache) Delete

func (cache *MemCache) Delete(key any)

Delete deletes the key and its value from the cache.

func (*MemCache) Get

func (cache *MemCache) Get(key any) (any, bool)

Get gets the value for the given key.

func (*MemCache) IsExist

func (c *MemCache) IsExist(key any) bool

IsExist 判断key是否存在

func (*MemCache) Range

func (cache *MemCache) Range(f func(key, value any) bool)

Range calls f sequentially for each key and value present in the cache. If f returns false, range stops the iteration.

func (*MemCache) Set

func (cache *MemCache) Set(key any, value any, duration time.Duration)

Set sets a value for the given key with an expiration duration. If the duration is 0 or less, it will be stored forever.

func (*MemCache) Value

func (c *MemCache) Value(key any) (any, bool)

Value 查找一个cache, value 返回的值

Jump to

Keyboard shortcuts

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