storage

package
v1.4.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSingleMock added in v1.1.1

func GetSingleMock(i int, path []byte, cfg config.Config) *model.Entry

func GetSingleMockWith added in v1.4.3

func GetSingleMockWith(i int, path []byte, cfg config.Config, brotli bool) *model.Entry

GetSingleMockWith builds a single mock Entry for the given index/path/config. Brotli compression is controlled by the brotli flag.

func LoadMocks added in v0.9.8

func LoadMocks(ctx context.Context, cfg config.Config, storage Storage, num int)

func LoadMocksWith added in v1.4.3

func LoadMocksWith(ctx context.Context, cfg config.Config, storage Storage, num int, brotli bool)

LoadMocksWith generates and stores num mock entries asynchronously.

func StreamEntryPointersConsecutive added in v1.2.0

func StreamEntryPointersConsecutive(ctx context.Context, cfg config.Config, path []byte, num int) <-chan *model.Entry

func StreamEntryPointersConsecutiveWith added in v1.4.3

func StreamEntryPointersConsecutiveWith(ctx context.Context, cfg config.Config, path []byte, num int, brotli bool) <-chan *model.Entry

StreamEntryPointersConsecutiveWith streams num entries (ordered) with given brotli flag.

Types

type DB added in v1.3.0

type DB struct {
	*lru.InMemoryStorage
	// contains filtered or unexported fields
}

func NewStorage added in v1.3.0

func NewStorage(ctx context.Context, cfg config.Config, upstream upstream.Upstream) *DB

func (*DB) Close added in v1.3.0

func (s *DB) Close() error

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

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

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

	// Close is stops internal workers and loggers (dump if necessary).
	Close() error
}

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

Directories

Path Synopsis
lru

Jump to

Keyboard shortcuts

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