hgcache

package
v0.0.0-...-6b5340c Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BytesView

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

func (BytesView) ByteSlice

func (v BytesView) ByteSlice() []byte

copy

func (BytesView) Len

func (v BytesView) Len() int

func (BytesView) String

func (v BytesView) String() string

type Getter

type Getter interface {
	Get(key string) ([]byte, error) // 根据key获取值
}

获取缓存数据接口,依赖注入,让用户自行实现获取方式

type GetterFunc

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

本地获取数据函数

func (GetterFunc) Get

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

type Group

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

func GetGroup

func GetGroup(name string) *Group

func NewGroup

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

func (*Group) Get

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

主要函数

获取缓存
策略:1,2,3
客户端访问-直接从本地缓存中取(本地缓存存在)
		 -(本地缓存不存在)是否从远程节点获取-(是)从远程获取-返回缓存
				                        -(否)回调函数getter,添加缓存-返回缓存

func (*Group) RegisterPeers

func (g *Group) RegisterPeers(peers PeerPicker)

type HttpPool

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

func NewHttpPool

func NewHttpPool(self string) *HttpPool

func (*HttpPool) Log

func (p *HttpPool) Log(format string, args ...interface{})

func (*HttpPool) PickPeer

func (p *HttpPool) PickPeer(key string) (PeerGetter, bool)

func (*HttpPool) ServeHTTP

func (p *HttpPool) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*HttpPool) Set

func (p *HttpPool) Set(peers ...string)

peers http://ip:port

type PeerGetter

type PeerGetter interface {
	Get(in *pb.Request, out *pb.Response) error
}

type PeerPicker

type PeerPicker interface {
	PickPeer(key string) (peer PeerGetter, ok bool)
}

Directories

Path Synopsis
rpc
pb

Jump to

Keyboard shortcuts

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