memory

package
v0.0.0-...-26e1b9e Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

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 GetMemoryCache

func GetMemoryCache() *Cache

func NewCache

func NewCache(config *Config) *Cache

NewCache 根据配置初始化一个内存型缓存示例,其中配置要求分片数应该是2的幂次方!

func (*Cache) Capacity

func (c *Cache) Capacity() int

func (*Cache) Close

func (c *Cache) Close() error

func (*Cache) Delete

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

func (*Cache) Get

func (c *Cache) Get(key string) (string, error)

func (*Cache) Iterator

func (c *Cache) Iterator() *EntryInfoIterator

func (*Cache) Len

func (c *Cache) Len() int

func (*Cache) Reset

func (c *Cache) Reset() error

func (*Cache) Set

func (c *Cache) Set(key, value string) error

func (*Cache) Stats

func (c *Cache) Stats() States

Stats 返回缓存的使用信息,比如缓存查询命中次数,查询miss次数,删除命中次数,删除miss次数

type Config

type Config struct {
	Shards             int           `json:"shards" yaml:"shards"`                         //存储的条目数量,值必须是2的幂
	LifeWindow         time.Duration `json:"lifeWindow" yaml:"lifeWindow"`                 //超时后条目被删除
	MaxEntriesInWindow int           `json:"maxEntriesInWindow" yaml:"maxEntriesInWindow"` //在 Life Window 中的最大数量
	MaxEntrySize       int           `json:"maxEntrySize" yaml:"maxEntrySize"`             //条目最大尺寸,以字节为单位
	HardMaxCacheSize   int           `json:"hardMaxCacheSize" yaml:"hardMaxCacheSize"`     //设置缓存最大值,以MB为单位,超过了不在分配内存。0表示无限制分配
	CleanWindow        time.Duration `json:"cleanWindow" yaml:"cleanWindow"`               //过期时间
}

func DefaultConfig

func DefaultConfig() Config

DefaultConfig 默认的缓存配置信息

type EntryInfoIterator

type EntryInfoIterator = bigcache.EntryInfoIterator //bigcache迭代器

type States

type States = bigcache.Stats //bigcache缓存使用统计数据

Jump to

Keyboard shortcuts

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