memkv

package
v1.3.90 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExpired           = errors.New("expired record")
	ErrInvalidRecordType = errors.New("invalid record type")
	ErrNotFound          = gorm.ErrRecordNotFound
)

Functions

func ListWithKeyPrefix

func ListWithKeyPrefix[T cachestore.ConsistentRecord](c *Cache, filterWithKeyPrefix T) ([]T, error)

Types

type Cache

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

Cache 结构,用于内存缓存

func NewCache

func NewCache(pCtx context.Context, client KvDbClientIf, conf CacheConf, records ...any) *Cache

NewCache 创建一个新的缓存实例

func (*Cache) CreateOrUpdate

func (c *Cache) CreateOrUpdate(rt cachestore.Record, expireAfterInSec int64) (exist bool, err error)

func (*Cache) Dump

func (c *Cache) Dump()

func (*Cache) Exist

func (c *Cache) Exist(filter cachestore.Record) (bool, error)

func (*Cache) Get

func (c *Cache) Get(filter cachestore.Record) (cachestore.Record, error)

func (*Cache) Set

func (c *Cache) Set(rt cachestore.Record, expireAfterInSec int64) error

func (*Cache) Update

func (c *Cache) Update(rt cachestore.Record) error

type CacheConf

type CacheConf struct {
	GcInterval int `vx_default:"10"` //in sec
}

type KvDbClientIf

type KvDbClientIf interface {
	Set(records any) error
	Get(filterAndDest any) error
	ListWithKeyPrefix(dest any, filter any, keyFieldName, keyPrefix string) error
	DeleteExpired(filter any) error
}

Jump to

Keyboard shortcuts

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