gcache

package module
v0.0.0-...-ce72360 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2022 License: MIT Imports: 17 Imported by: 0

README

gcache

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterPeerPicker

func RegisterPeerPicker(fn func() PeerPicker)

Types

type AtomicInt

type AtomicInt int64

func (*AtomicInt) Add

func (i *AtomicInt) Add(n int64)

func (*AtomicInt) Get

func (i *AtomicInt) Get() int64

func (*AtomicInt) String

func (i *AtomicInt) String() string

type ByteView

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

A ByteView holds an immutable view of bytes. Internally it wraps either a []byte or a string, but that detail is invisible to callers.

A ByteView is meant to be used as a value type, not a pointer (like a time.Time).

func (ByteView) At

func (v ByteView) At(i int) byte

At returns the byte at index i.

func (ByteView) ByteSlice

func (v ByteView) ByteSlice() []byte

ByteSlice returns a copy of the data as a byte slice.

func (ByteView) Copy

func (v ByteView) Copy(dest []byte) int

Copy copies b into dest and returns the number of bytes copied.

func (ByteView) Equal

func (v ByteView) Equal(b2 ByteView) bool

Equal returns whether the bytes in b are the same as the bytes in b2.

func (ByteView) EqualBytes

func (v ByteView) EqualBytes(b2 []byte) bool

EqualBytes returns whether the bytes in b are the same as the bytes in b2.

func (ByteView) EqualString

func (v ByteView) EqualString(s string) bool

EqualString returns whether the bytes in b are the same as the bytes in s.

func (ByteView) Len

func (v ByteView) Len() int

Len returns the view's length.

func (ByteView) ReadAt

func (v ByteView) ReadAt(p []byte, off int64) (n int, err error)

ReadAt implements io.ReaderAt on the bytes in v.

func (ByteView) Reader

func (v ByteView) Reader() io.ReadSeeker

Reader returns an io.ReadSeeker for the bytes in v.

func (ByteView) Slice

func (v ByteView) Slice(from, to int) ByteView

Slice slices the view between the provided from and to indices.

func (ByteView) SliceFrom

func (v ByteView) SliceFrom(from int) ByteView

SliceFrom slices the view from the provided index until the end.

func (ByteView) String

func (v ByteView) String() string

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

func (ByteView) WriteTo

func (v ByteView) WriteTo(w io.Writer) (n int64, err error)

WriteTo implements io.WriterTo on the bytes in v.

type CacheStats

type CacheStats struct {
	Bytes     int64
	Items     int64
	Gets      int64
	Hits      int64
	Evictions int64
}

type Getter

type Getter interface {
	Get(ctx context.Context, key string) (ByteView, error)
}

type GetterFunc

type GetterFunc func(ctx context.Context, key string) (ByteView, error)

func (GetterFunc) Get

func (f GetterFunc) Get(ctx context.Context, key string) (ByteView, 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

NewGroup cacheBytes 当前group最大缓存字节数,getter 缓存未命中时用于回源读数据的回调函数

func (*Group) Get

func (g *Group) Get(ctx context.Context, key string) (ByteView, error)

func (*Group) Name

func (g *Group) Name() string

type HTTPPool

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

func NewHTTPPool

func NewHTTPPool(self string) *HTTPPool

func NewHTTPPoolOpts

func NewHTTPPoolOpts(self string, o *HTTPPoolOptions) *HTTPPool

func (*HTTPPool) Add

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

func (*HTTPPool) PickPeer

func (p *HTTPPool) PickPeer(key string) ProtoGetter

func (*HTTPPool) Remove

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

func (*HTTPPool) ServeHTTP

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

func (*HTTPPool) Set

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

type HTTPPoolOptions

type HTTPPoolOptions struct {
	BasePath string
	Replicas int
	HashFn   consistenthash.Hash
}

type PeerPicker

type PeerPicker interface {
	PickPeer(key string) ProtoGetter
}

type ProtoGetter

type ProtoGetter interface {
	Get(ctx context.Context, in *pb.Request, out *pb.Response) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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