peanutcache

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2021 License: MIT Imports: 15 Imported by: 0

README

peanutcache

peanutcache是一个简单的分布式缓存,参考groupcache实现。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DestroyGroup added in v0.1.0

func DestroyGroup(name string)

func NewClient

func NewClient(service string) *client

func NewServer

func NewServer(addr string) (*server, error)

NewServer 创建cache的svr 若addr为空 则使用defaultAddr

Types

type ByteView

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

func (ByteView) ByteSlice

func (v ByteView) ByteSlice() []byte

ByteSlice 返回一份[]byte的副本(深拷贝)

func (ByteView) Len

func (v ByteView) Len() int

func (ByteView) String

func (v ByteView) String() string

type Fetcher

type Fetcher interface {
	Fetch(group string, key string) ([]byte, error)
}

Fetcher 定义了从远端获取缓存的能力 所以每个Peer应实现这个接口

type Group

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

Group 提供命名管理缓存/填充缓存的能力

func GetGroup

func GetGroup(name string) *Group

GetGroup 获取对应命名空间的缓存

func NewGroup

func NewGroup(name string, maxBytes int64, retriever Retriever) *Group

NewGroup 创建一个新的缓存空间

func (*Group) Get

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

func (*Group) RegisterSvr

func (g *Group) RegisterSvr(p Picker)

RegisterSvr 为 Group 注册 Server

type Picker

type Picker interface {
	Pick(key string) (Fetcher, bool)
}

Picker 定义了获取分布式节点的能力

type Retriever

type Retriever interface {
	// contains filtered or unexported methods
}

Retriever 要求对象实现从数据源获取数据的能力

type RetrieverFunc

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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