tinyCache

package
v0.0.0-...-e716e59 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteView

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

A ByteView holds an immutable view of bytes.

func (ByteView) ByteSlice

func (v ByteView) ByteSlice() []byte

ByteSlice returns a copy of the data as a byte slice. b 是只读的,使用 ByteSlice() 方法返回一个拷贝,防止缓存值被外部程序修改

func (ByteView) Len

func (v ByteView) Len() int

Len returns the view's length 在 lru.Cache 的实现中,要求被缓存对象必须实现 Value 接口,即 Len() int 方法,返回其所占的内存大小

func (ByteView) String

func (v ByteView) String() string

String returns the data as a string, making a copy if necessary.

type Getter

type Getter interface {
	Get(key string) ([]byte, error)
}

A Getter loads data for a key. 定义接口 Getter

type GetterFunc

type GetterFunc func(key string) ([]byte, error)

A GetterFunc implements Getter with a function. 定义函数类型 GetterFunc,并实现 Getter 接口的 Get 方法 函数类型实现某一个接口,称之为接口型函数,方便使用者在调用时既能够传入函数作为参数,也能够传入实现了该接口的结构体作为参数

func (GetterFunc) Get

func (f GetterFunc) Get(key string) ([]byte, error)

Get implements Getter interface function 回调函数(callback),在缓存不存在时,调用这个函数,得到源数据

type Group

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

A Group is a cache namespace and associated data loaded spread over 一个 Group 可以认为是一个缓存的命名空间

func GetGroup

func GetGroup(name string) *Group

GetGroup returns the named group previously created with NewGroup, or nil if there's no such group. GetGroup 用来特定名称的 Group,这里使用了只读锁 RLock(),因为不涉及任何冲突变量的写操作

func NewGroup

func NewGroup(name string, cacheBytes int64, getter Getter) *Group

NewGroup create a new instance of Group 构建函数 NewGroup 用来实例化 Group,并且将 group 存储在全局变量 groups 中

func (*Group) Get

func (g *Group) Get(key string) (ByteView, error)

Get value for a key from cache

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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