storage

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2025 License: Apache-2.0 Imports: 21 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
}

func NewDumper

func NewDumper(cfg *config.Cache, 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

func (*Dump) LoadVersion added in v1.0.3

func (d *Dump) LoadVersion(ctx context.Context, v string) error

type Dumper

type Dumper interface {
	Dump(ctx context.Context) error
	Load(ctx context.Context) error
	LoadVersion(ctx context.Context, v string) error
}

type Storage

type Storage interface {
	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.Entry, hit bool)

	// Set stores a new response in the cache and returns a releaser for managing resource lifetime.
	// 1. You definitely cannot use 'inEntry' after use in Set due to it can be removed, you will receive a cache entry on hit!
	// 2. Use Release and Remove for manage Entry lifetime.
	Set(inEntry *model.Entry) (persisted bool)

	// Remove is removes one element.
	Remove(*model.Entry) (freedBytes int64, hit 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

	RealLen() 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.Entry, ok bool)

	WalkShards(ctx context.Context, fn func(key uint64, shard *sharded.Shard[*model.Entry]))
}

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