cache

package
v2.0.15 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidDataType = errors.New("invalid data type")
View Source
var (
	FlushWithoutChangeIntervalSeconds int64 = 60
)

Functions

func CommonGet

func CommonGet[V msg.Value](c *Cache, key string, timeoutSecond int64, handler msg.Handler[V]) any

func Delete

func Delete(c *Cache, keys ...string)

func Get

func Get(c *Cache, key string, timeoutSecond int64) (value interface{}, effective, exists bool)

func Length

func Length(c *Cache) int64

func Set

func Set[V msg.Value](c *Cache, key string, value V) (err error)

Types

type Bucket

type Bucket struct {
	Data map[string]*Entry `msg:"data"`
	// contains filtered or unexported fields
}

func (*Bucket) DecodeMsg

func (z *Bucket) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Bucket) EncodeMsg

func (z *Bucket) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Bucket) Marshal

func (b *Bucket) Marshal() (data []byte, err error)

func (*Bucket) MarshalMsg

func (z *Bucket) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Bucket) Msgsize

func (z *Bucket) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Bucket) UnmarshalMsg

func (z *Bucket) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Cache

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

func New

func New(localDir string, flushInterval time.Duration) *Cache

func (*Cache) Flush

func (c *Cache) Flush()

type Entry

type Entry struct {
	UpdatedAt int64       `msg:"u"`
	CreatedAt int64       `msg:"c"`
	Value     interface{} `msg:"v"`
	// contains filtered or unexported fields
}

func (*Entry) DecodeMsg

func (z *Entry) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (Entry) EncodeMsg

func (z Entry) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (Entry) MarshalMsg

func (z Entry) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Entry) Msgsize

func (z Entry) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Entry) UnmarshalMsg

func (z *Entry) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*Entry) Val

func (e *Entry) Val() msg.Map

type Info

type Info struct {
	LocalDir       string           `json:"localDir"`
	FlushInterval  string           `json:"flushInterval"`
	Length         int64            `json:"length"`
	LatestSyncTime string           `json:"latestSyncTime"`
	Keys           map[int][]string `json:"keys"`
	Items          []Item           `json:"items"`
}

func InfoCache

func InfoCache(c *Cache) Info

type Item

type Item struct {
	Key       string `json:"key"`
	UpdatedAt int64  `json:"updatedAt"`
	UpdateCnt uint64 `json:"updateCount"`
	HitCnt    uint64 `json:"hitCount"`
	MissCnt   uint64 `json:"missCount"`
	CreatedAt int64  `msg:"createdAt"`
	Value     string `msg:"value"`
}

Jump to

Keyboard shortcuts

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