lfu

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: MIT Imports: 10 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrValueReceiverNil = errors.New("cache: value receiver must not nil pointer")
)

Functions

This section is empty.

Types

type Config added in v0.4.0

type Config struct {
	// DriverName set it to register to cache manager.
	DriverName string `yaml:"driverName" json:"driverName"`
	Size       int    `yaml:"size" json:"size"`
	Samples    int    `yaml:"samples" json:"samples"`
	// TTL is default to set item ttl, if you use no expired cache, this value is not used.
	TTL       time.Duration `yaml:"ttl" json:"ttl"`
	Deviation int64         `yaml:"deviation" json:"deviation"`
	// Subsidiary indicate whether the cache is a subsidiary cache,
	// if true, the cache will not be registered to cache manager and ttl will be the max ttl.
	Subsidiary bool `yaml:"subsidiary" json:"subsidiary"`
}

Config is the configuration for TinyLFU cache

type TinyLFU

type TinyLFU struct {
	Config
	// contains filtered or unexported fields
}

TinyLFU is a cache implementation of TinyLFU algorithm. It forces the cache data to have an expiration time.

Default ttl is 1 minute.Notice that the ttl will be less the setting, randomly reduced by a value between 0 and the offset.

func NewTinyLFU

func NewTinyLFU(cnf *conf.Configuration) (*TinyLFU, error)

func (*TinyLFU) Apply

func (c *TinyLFU) Apply(cnf *conf.Configuration) error

Apply implements the conf.Configurable interface

func (*TinyLFU) Clean

func (c *TinyLFU) Clean()

func (*TinyLFU) Del

func (c *TinyLFU) Del(_ context.Context, key string) error

func (*TinyLFU) Get

func (c *TinyLFU) Get(ctx context.Context, key string, value any, opts ...cache.Option) (err error)

Get returns the value for the given key, or ErrCacheMiss. If the value is nil, the value will not be set

func (*TinyLFU) GetInner

func (c *TinyLFU) GetInner(_ context.Context, key string, value any, raw bool) error

func (*TinyLFU) Has

func (c *TinyLFU) Has(_ context.Context, key string) bool

func (*TinyLFU) IsNotFound

func (c *TinyLFU) IsNotFound(err error) bool

func (*TinyLFU) Register added in v0.4.1

func (c *TinyLFU) Register() error

Register cache to cache manager

func (*TinyLFU) Set

func (c *TinyLFU) Set(ctx context.Context, key string, value any, opts ...cache.Option) error

Set sets the value for the given key.ttl is the expiration time, if ttl is zero, the default ttl will be used. the ttl will be less the setting,randomly reduced by a value between 0 and the offset.

func (*TinyLFU) SetInner

func (c *TinyLFU) SetInner(_ context.Context, key string, value any, ttl time.Duration, opt *cache.Options) error

SetInner sets the value for the given key.ttl is the expiration time, if ttl is zero, the default ttl will be used.

Jump to

Keyboard shortcuts

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