proc

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoExpiration time.Duration = -1 //没有过期标识

)

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(defaultExpiration, gcInterval time.Duration) (c *Cache)

新建一个缓存系统

func (*Cache) Add

func (c *Cache) Add(k string, v interface{}, d time.Duration) error

新增操作,如果数据项已存在,则报错

func (*Cache) Count

func (c *Cache) Count() int

返回缓存中数据项的数量

func (*Cache) Delete

func (c *Cache) Delete(k string)

删除操作

func (*Cache) DeleteExpired

func (c *Cache) DeleteExpired()

过期缓存删除

func (*Cache) Flush

func (c *Cache) Flush()

清空缓存

func (*Cache) Get

func (c *Cache) Get(k string) (interface{}, bool)

获取缓存操作

func (*Cache) Load

func (c *Cache) Load(r io.Reader) error

从io.Reader读取

func (*Cache) LoadFromFile

func (c *Cache) LoadFromFile(filename string) error

从文件中读取

func (*Cache) Replace

func (c *Cache) Replace(k string, v interface{}, d time.Duration) error

替换操作

func (*Cache) Save

func (c *Cache) Save(w io.Writer) (err error)

将缓存数据写入io.Writer中

func (*Cache) SaveToFile

func (c *Cache) SaveToFile(filename string) error

序列化到文件

func (*Cache) Set

func (c *Cache) Set(k string, v interface{}, d time.Duration, isSlide bool)

设置缓存数据项,存在则直接覆盖 ,d 过期时间 isSlide 是否滑动过期

func (*Cache) StopGc

func (c *Cache) StopGc()

停止gc

type Item

type Item struct {
	Object     interface{}   //数据项
	Expiration int64         //数据项过期时间(0永不过期)
	IsSlide    bool          //是否滑动过期
	Dur        time.Duration //过期期限
}

func (Item) IsExpired

func (item Item) IsExpired() bool

Jump to

Keyboard shortcuts

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