group

package
v0.0.0-...-1173c81 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Getter

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

Getter is a interface used to get data from different datasource eg: mysql, redis, pgsql

type GetterFunc

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

A GetterFunc implements Getter with a function

func (GetterFunc) Get

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

Implement Getter method Get, as a Getter function?

type Group

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

A Group means a cache namespace,every group own a unique name eg: StudentGroup,InfoGroup, ....

func GetGroup

func GetGroup(name string) *Group

GetGroup用来特定名称的 Group, 这里使用了只读锁 RLock(),因为不涉及任何冲突变量的写操作。

func NewGroup

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

func (*Group) Get

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

func (*Group) GetLocally

func (g *Group) GetLocally(key string) (*core.ByteView, error)

GetLocally Get data from user define data source and set data into mainCache(by populateCache method)

func (*Group) Load

func (g *Group) Load(key string) (value *core.ByteView, err error)

load key using PickPeer to find node and load data

func (*Group) PopulateCache

func (g *Group) PopulateCache(key string, value core.ByteView)

func (*Group) RegisterPeers

func (g *Group) RegisterPeers(peers communication.PeerPicker)

Register HTTPPool into Group which is peers(peer picker)

type HTTPGetter

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

func (*HTTPGetter) Get

func (h *HTTPGetter) Get(group, key string) ([]byte, error)

baseURL --> remote endpoint use http.Get to retrieve return value

type HTTPPool

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

func NewHTTPPool

func NewHTTPPool(self string) *HTTPPool

NewHTTPPool initializes an HTTP pool of peers.

func (*HTTPPool) Log

func (p *HTTPPool) Log(format string, v ...interface{})

func (*HTTPPool) PickPeer

func (p *HTTPPool) PickPeer(key string) (communication.PeerGetter, bool)

包装了一致性哈希算法的 Get() 方法,根据具体的 key,选择节点, 返回节点对应的 HTTP 客户端。

func (*HTTPPool) ServeHTTP

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

创建任意类型 server,并实现 ServeHTTP 方法。

func (*HTTPPool) Set

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

Set Updates the pool's list of peers Set() 方法实例化了一致性哈希算法,并且添加了传入的节点。 并为每一个节点创建了一个 HTTP 客户端 httpGetter。

Jump to

Keyboard shortcuts

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