cache

package
v1.1.16 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UnknownCacheType     = errors.New("unknown cache type")
	UnknownCompress      = errors.New("unknown compress type")
	UnknownSerializeType = errors.New("unknown serialize type")
	UnknownRemoteType    = errors.New("unknown remote type")
	ErrNotImplement      = errors.New("not implement")
	ErrCacheNotFound     = errors.New("not found cache to use")
	ErrCallbackNotFound  = errors.New("not found callback function")
)

Functions

func AppName

func AppName(name string) utils.OptionFunc[initOption]

func Construct

func Construct(ctx context.Context, confs map[string]*Conf, _ ...utils.OptionExtender) func()

Construct cache only check some configures

func Expired

func Expired[K constraint.Sortable](expired time.Duration) utils.OptionFunc[option[K]]

func KeyExpired

func KeyExpired[K constraint.Sortable](keyExpired map[K]time.Duration) utils.OptionFunc[option[K]]

Types

type Cachable

type Cachable[K constraint.Sortable, T any, TS ~[]T] interface {
	Get(ctx context.Context, keys []K, cb callback[K, T]) TS
	GetAll(ctx context.Context, cb callback[K, T]) TS
	Set(ctx context.Context, kv map[K]T, opts ...utils.OptionExtender) (failure []K)
	Del(ctx context.Context, keys ...K) (failure []K)
	Clear(ctx context.Context) (failure []K)
}

func New

func New[K constraint.Sortable, T any, TS ~[]T](name string, opts ...utils.OptionExtender) Cachable[K, T, TS]

type Conf

type Conf struct {
	Size           int        `yaml:"size" json:"size" toml:"size" default:"10000"`
	Expired        string     `yaml:"expired" json:"expired" toml:"expired" default:"1h"`
	Version        int        `yaml:"version" json:"version" toml:"version"`
	CacheType      cacheType  `yaml:"type" json:"type" toml:"type" default:"local"`
	RemoteType     remoteType `yaml:"remote_type" json:"remote_type" toml:"remote_type" default:"redis"`
	RemoteInstance string     `yaml:"remote_instance" json:"remote_instance" toml:"remote_instance"`
	LocalEvictType string     `yaml:"local_evict_type" json:"local_evict_type" toml:"local_evict_type" default:"arc"`
	Compress       string     `yaml:"compress" json:"compress" toml:"compress"`
	SerializeType  string     `yaml:"serialize_type" json:"serialize_type" toml:"serialize_type"`
	Callback       string     `yaml:"callback" json:"callback" toml:"callback"`
	LogInstance    string     `yaml:"log_instance" json:"log_instance" toml:"log_instance" default:"default"`
}

Jump to

Keyboard shortcuts

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