yeeCache

package
v0.0.0-...-89bd919 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

yeeCache 文件缓存类

yeeCache 内存缓存类

Index

Constants

View Source
const (
	DefaultExpiration time.Duration = 0
	NoExpiration      time.Duration = -1
)

Variables

This section is empty.

Functions

func FileTtlCache

func FileTtlCache(fileName string, f func() (b []byte, ttl time.Duration, err error)) (b []byte, err error)

FileTtlCache 文件ttl缓存

Types

type Item

type Item struct {
	Object     interface{}
	Expiration int64
}

Item 缓存的数据的结构

func (*Item) Expired

func (item *Item) Expired() bool

Expired 判断数据是否过期

type KV

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

type MemoryCache

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

MemoryCache 内存缓存

func NewMemoryCache

func NewMemoryCache(defaultExpiration, cleanupInterval time.Duration) *MemoryCache

NewMemoryCache 初始化内存缓存

func NewMemoryCacheWithMap

func NewMemoryCacheWithMap(defaultExpiration, cleanupInterval time.Duration, items map[string]Item) *MemoryCache

NewMemoryCache 初始化内存缓存 可以传入map数据

func (MemoryCache) Add

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

Add 添加数据,如果已经存在,则报错

func (MemoryCache) Delete

func (c MemoryCache) Delete(k string)

Delete 删除某个key

func (MemoryCache) DeleteExpired

func (c MemoryCache) DeleteExpired()

DeleteExpired 删除过期的数据

func (MemoryCache) Flush

func (c MemoryCache) Flush()

Flush 清空全部的缓存

func (MemoryCache) Get

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

Get 获取数据,如果不存在,返回nil,false

func (MemoryCache) ItemCount

func (c MemoryCache) ItemCount() int

ItemCount 获取已缓存的数量 其中包含了那些已经过期但是没有被清理的

func (MemoryCache) Items

func (c MemoryCache) Items() map[string]Item

Items 获取全部未过期的数据

func (MemoryCache) Replace

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

Replace 替换

func (MemoryCache) Set

func (c MemoryCache) Set(k string, v interface{}, d time.Duration)

Set 存储数据,如果存在则替换

func (MemoryCache) SetDefault

func (c MemoryCache) SetDefault(k string, v interface{})

SetDefault 默认过期时间

Jump to

Keyboard shortcuts

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