storage

package
v0.9.9 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadMocks added in v0.9.8

func LoadMocks(ctx context.Context, config *config.Cache, backend repository.Backender, storage Storage, num int)

Types

type Dump

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

Dump implements persistence with versioned directories.

func NewDumper

func NewDumper(cfg *config.Cache, storage Storage, backend repository.Backender) *Dump

NewDumper constructs a Dump.

func (*Dump) Dump

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

Dump writes all entries into a new versioned directory. It then rotates old dirs, keeping only the latest cfg.MaxVersions.

func (*Dump) Load

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

Load reads from the latest versioned dir; if none, falls back to mock.

type Dumper

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

Dumper defines dump & load operations.

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, storage Storage) *Refresh

NewRefresher constructs a Refresh.

func (*Refresh) Run

func (r *Refresh) Run() *Refresh

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 {
	// contains filtered or unexported methods
}

type Storage

type Storage interface {
	// 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)

	// 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)

	// Clear is removes all cache entries from the storage.
	Clear()

	// 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

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

	WalkShards(fn func(key uint64, shard *sharded.Shard[*model.VersionPointer]))
}

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