storage

package
v0.8.6 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Algorithm

type Algorithm string

Algorithm is the string type for caching algorithms labels.

const (
	// LRU is the constant for Least Recently Used.
	LRU Algorithm = "lru"

	// MRU is the constant for Most Recently Used.
	MRU Algorithm = "mru"

	// LFU is the constant for Least Frequently Used.
	LFU Algorithm = "lfu"

	// MFU is the constant for Most Frequently Used.
	MFU Algorithm = "mfu"
)

type Dump

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

func NewDumper

func NewDumper(
	cfg *config.Cache,
	shardedMap *sharded.Map[*model.Response],
	storage *lru.Storage,
	backend repository.Backender,
) *Dump

func (*Dump) Dump

func (d *Dump) Dump(ctx context.Context) error

Dump writes cache entries to disk based on the configured format and rotation policy.

func (*Dump) Load

func (d *Dump) Load(ctx context.Context) error

Load restores cache entries from disk based on configuration.

type Dumper

type Dumper interface {
	Dump(ctx context.Context) error
	Load(ctx context.Context) error
}

type Evict

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

func NewEvictor

func NewEvictor(ctx context.Context, cfg *config.Cache, db Storage, balancer lru.Balancer) *Evict

func (*Evict) Run

func (e *Evict) Run()

Run launches multiple evictor goroutines for concurrent eviction.

func (*Evict) ShouldEvict

func (e *Evict) ShouldEvict() bool

ShouldEvict [HOT PATH METHOD] (max stale value = 25ms) checks if current Weight usage has reached or exceeded the threshold.

type EvictionStat

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

EvictionStat carries statistics for each eviction batch.

type Evictor

type Evictor interface {
	Run()
}

type Refresh

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

Refresh is responsible for background refreshing of cache entries. It periodically samples random shards and randomly selects "cold" entries (from the end of each shard's Storage list) to refreshItem if necessary.

func NewRefresher

func NewRefresher(ctx context.Context, cfg *config.Cache, balancer lru.Balancer) *Refresh

NewRefresher constructs a Refresh.

func (*Refresh) Run

func (r *Refresh) Run()

Run starts the refresher background loop. It runs a logger (if debugging is enabled), spawns a provider for sampling shards, and continuously processes shard samples for candidate responses to refreshItem.

type Refresher

type Refresher interface {
	Run()
}

type Storage

type Storage interface {
	// Run starts storage background worker (just logging at now).
	Run()

	// Get attempts to retrieve a cached response for the given request.
	// Returns the response, a releaser for safe concurrent access, and a hit/miss flag.
	Get(req *model.Request) (resp *model.Response, isHit bool)

	// Set stores a new response in the cache and returns a releaser for managing resource lifetime.
	Set(resp *model.Response)

	// Remove is removes one element.
	Remove(req *model.Response) (freedBytes int64, isHit bool)

	// Stat returns bytes usage and num of items in storage.
	Stat() (bytes int64, length int64)

	// Mem - return stored value (refreshes every 100ms).
	Mem() int64

	// RealMem - calculates and return value.
	RealMem() int64
}

Storage is a generic interface for cache storages. It supports typical Get/Set operations with reference management.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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