buffer

package module
v0.0.0-...-45634ab Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: MIT Imports: 7 Imported by: 0

README

buffer

The golang message cache package.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidValue = errors.New("invalid option value")

Functions

This section is empty.

Types

type Buffer

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

func New

func New(options ...OptionFunc) (*Buffer, error)

func (*Buffer) Exist

func (b *Buffer) Exist(x int64) bool

func (*Buffer) Read

func (b *Buffer) Read(x int64) proto.Message

func (*Buffer) Tidy

func (b *Buffer) Tidy()

Tidy 整理删除无效元素

func (*Buffer) Write

func (b *Buffer) Write(msg proto.Message) int64

type Exist

type Exist interface {
	Exist(x int64) bool
}

type Option

type Option struct {
	Len     int     // 理想/健康长度
	Cap     int     // 容量,超过容量会触发缩容到Len
	Timeout float64 // 缓存过期时间
	Limit   int64   // 缓存最大访问次数限制
}

func (*Option) Validate

func (op *Option) Validate() bool

type OptionFunc

type OptionFunc func(option *Option)

func DefaultOption

func DefaultOption() OptionFunc

type Reader

type Reader interface {
	Read(x int64) proto.Message
}

type ReaderWriter

type ReaderWriter interface {
	Reader
	Writer
	Exist
}

type Single

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

Single 缓存单例

func NewSingle

func NewSingle(options ...OptionFunc) (*Single, error)

func (*Single) Exist

func (s *Single) Exist(x int64) bool

func (*Single) Read

func (s *Single) Read(x int64) proto.Message

func (*Single) Write

func (s *Single) Write(msg proto.Message) int64

type Writer

type Writer interface {
	Write(proto.Message) int64
}

Jump to

Keyboard shortcuts

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