cache

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PUT = iota + 1
	GET
	DEL
	EVICT
)

Variables

This section is empty.

Functions

func ToInt64

func ToInt64(b []byte) (int64, bool)

ToInt64 - convert bytes to int64

Types

type Cache

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

Cache - concurrent cache structure

func NewLRUCache

func NewLRUCache(bucketCnt, capPerBkt uint16, expiration ...time.Duration) *Cache

NewLRUCache - create lru cache `bucketCnt` is buckets that shard items to reduce lock racing `capPerBkt` is length of each bucket, can store `capPerBkt * bucketCnt` count of items in Cache at most optional `expiration` is item alive time (and we only use lazy eviction here), default `0` stands for permanent

func (*Cache) Del

func (c *Cache) Del(key string)

Del - delete item by key from cache

func (*Cache) Get

func (c *Cache) Get(key string) (any, bool)

Get - get value of key from cache with result

func (*Cache) GetBytes

func (c *Cache) GetBytes(key string) ([]byte, bool)

GetBytes - get bytes value of key from cache with result

func (*Cache) GetInt64

func (c *Cache) GetInt64(key string) (int64, bool)

GetInt64 - get value of key from cache with result

func (*Cache) Inspect

func (c *Cache) Inspect(ipr inspector)

Inspect - to inspect the actions

func (*Cache) LRU2

func (c *Cache) LRU2(capPerBkt uint16) *Cache

LRU2 - add LRU-2 support (especially LRU-2 that when item visited twice it moves to upper-level-cache) `capPerBkt` is length of each LRU-2 bucket, can store extra `capPerBkt * bucketCnt` count of items in Cache at most

func (*Cache) Len

func (c *Cache) Len() int

Len

func (*Cache) Put

func (c *Cache) Put(key string, val any)

Put - put an item into cache

func (*Cache) PutBytes

func (c *Cache) PutBytes(key string, b []byte)

PutBytes - put a bytes item into cache

func (*Cache) PutEx

func (c *Cache) PutEx(key string, val any, ex time.Duration)

PutEx - put an item into cache

func (*Cache) PutExAt

func (c *Cache) PutExAt(key string, val any, ea int64)

PutExAt - put an item into cache

func (*Cache) PutInt64

func (c *Cache) PutInt64(key string, d int64)

PutInt64 - put a digit item into cache

func (*Cache) Walk

func (c *Cache) Walk(walker func(key string, ifc any, bytes []byte, expireAt int64) bool)

Walk - calls f sequentially for each valid item in the lru cache, return false to stop iteration for every bucket

Jump to

Keyboard shortcuts

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