ycache

package
v0.0.0-...-1b9858f Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultInterval = time.Second

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Has returns whether the key exists.
	Has(key string) (has bool)
	// Set key-value, if the key exists, it will be overwritten.
	Set(key string, val any, opts ...ItemOption)
	// Get returns the value of the key, if the key does not exist, it returns false.
	Get(key string) (val any, has bool)
	// Del deletes the key.
	Del(key string) (ok bool)
	// GetDel returns the value of the key and deletes the key.
	GetDel(key string) (val any, has bool)
	// GetSet returns the value of the key and sets the new value.
	GetSet(key string, newVal any, opts ...ItemOption) (oldVal any, has bool)
	// SetX sets the key-value, if the key exists, it will not be overwritten.
	SetX(key string, val any, opts ...ItemOption) (ok bool)
	// DelExpired deletes the expired key.
	DelExpired(key string) (has, exp bool)
	// All returns all key-value.
	All() (kvs map[string]any)
	// Len returns the number of key-value.
	Len() int
	// Clear deletes all key-value.
	Clear() int
	// TTL returns the remaining time of the key.
	TTL(key string) (ttl time.Duration, has bool)
	// Expire sets the remaining time of the key.
	Expire(key string, ttl time.Duration) (ok bool)
}

Cache interface

func New

func New(opts ...Option) Cache

type ExpireFun

type ExpireFun func(key string, val any)

ExpireFun item expire callback

type ItemOption

type ItemOption func(i *item)

ItemOption item option

func WithItemDur

func WithItemDur(d time.Duration) ItemOption

WithItemDur set item expire duration

func WithItemFun

func WithItemFun(h ExpireFun) ItemOption

WithItemFun set item expire callback

func WithItemTime

func WithItemTime(t time.Time) ItemOption

WithItemTime set item expire time

type Option

type Option func(opts *options)

func WithExpireFun

func WithExpireFun(h ExpireFun) Option

WithExpireFun set default expire callback

func WithInterval

func WithInterval(d time.Duration) Option

WithInterval set expire check interval

func WithLogger

func WithLogger(l ylog.Logger) Option

WithLogger set logger

func WithShardSize

func WithShardSize(count int) Option

WithShardSize set shard size

Jump to

Keyboard shortcuts

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