storage

package
v0.9.6 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 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 Dump

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

func NewDumper

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

func (*Dump) Dump

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

func (*Dump) Load

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

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. Communication: provider->consumer (MPSC).

func NewRefresher

func NewRefresher(ctx context.Context, cfg *config.Cache, balancer lru.Balancer, storage Storage) *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(*model.Entry) (entry *model.VersionPointer, ok bool)

	// GetRand returns a random elem from the map.
	GetRand() (entry *model.VersionPointer, ok bool)

	// Set stores a new response in the cache and returns a releaser for managing resource lifetime.
	// 1. You definitely cannot use 'request' after use in Set due to it can be removed, you will receive a cache entry on hit!
	Set(request *model.VersionPointer) (entry *model.VersionPointer)

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

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

	// Len - return stored value (refreshes every 100ms).
	Len() 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