memory

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const KB = 1 << 10
View Source
const MB = 1 << 20

Variables

View Source
var (
	ErrLRUCacheNotExists = errors.New("指定LRUCache不存在,或未初始化")
	ErrSizeOverflow      = errors.New("LRU容量溢出")
)

Functions

func Init

func Init(conf []Config) error

Init 初始化数据库

Types

type Config

type Config struct {
	Name     string `json:"name" toml:"name"`
	Capacity uint64 `json:"capacity" toml:"capacity"`
}

type LRU

type LRU interface {
	Get(key string) (Value, bool)
	Exists(key string) bool
	Set(key string, val []byte, expiration int32) error
	Delete(key string) bool
	Flush()
	Size() uint64
	Capacity() uint64
}

func LRUCache

func LRUCache(name string) (LRU, error)

LRUCache 通过名称获取LRU实例

type LRUImpl

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

LRUImpl 定义LRU缓存结构体

func (*LRUImpl) Capacity

func (lru *LRUImpl) Capacity() uint64

Capacity 获取lru容量

func (*LRUImpl) Delete

func (lru *LRUImpl) Delete(key string) bool

Delete 删除缓存

func (*LRUImpl) Exists added in v0.2.38

func (lru *LRUImpl) Exists(key string) bool

Exists 获取缓存

func (*LRUImpl) Flush

func (lru *LRUImpl) Flush()

Flush 清空缓存

func (*LRUImpl) Get

func (lru *LRUImpl) Get(key string) (v Value, ok bool)

Get 获取缓存

func (*LRUImpl) Set

func (lru *LRUImpl) Set(key string, val []byte, expiration int32) error

Set 设置缓存

func (*LRUImpl) Size

func (lru *LRUImpl) Size() uint64

Size 获取lru已使用大小

type Manager

type Manager struct {
	sync.Map
}

type Value

type Value []byte

Value 定义Value类型为byte数组

func (Value) String

func (v Value) String() string

Jump to

Keyboard shortcuts

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