memory

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAdapter

func NewAdapter(opts ...AdapterOptions) (cache.Adapter, error)

NewAdapter initializes memory adapter.

Types

type Adapter

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

Adapter is the memory adapter data structure.

func (*Adapter) Get

func (a *Adapter) Get(key uint64) ([]byte, bool)

Get implements the cache Adapter interface Get method.

func (*Adapter) Purge

func (a *Adapter) Purge()

Purge implements the Adapter interface Purge method

func (*Adapter) Release

func (a *Adapter) Release(key uint64)

Release implements the Adapter interface Release method.

func (*Adapter) Set

func (a *Adapter) Set(key uint64, response []byte, expiration time.Time)

Set implements the cache Adapter interface Set method.

type AdapterOptions

type AdapterOptions func(a *Adapter) error

AdapterOptions is used to set Adapter settings.

func AdapterWithAlgorithm

func AdapterWithAlgorithm(alg Algorithm) AdapterOptions

AdapterWithAlgorithm sets the approach used to select a cached response to be evicted when the capacity is reached.

func AdapterWithCapacity

func AdapterWithCapacity(cap int) AdapterOptions

AdapterWithCapacity sets the maximum number of cached responses.

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 Response added in v1.0.3

type Response struct {
	// Value is the cached response value.
	Value []byte

	// Expiration is the cached response expiration date.
	Expiration time.Time

	// LastAccess is the last date a cached response was accessed.
	// Used by LRU and MRU algorithms.
	LastAccess time.Time

	// Frequency is the count of times a cached response is accessed.
	// Used for LFU and MFU algorithms.
	Frequency int
}

func BytesToResponse added in v1.0.3

func BytesToResponse(b []byte) Response

BytesToResponse converts bytes array into Response data structure.

func (Response) Bytes added in v1.0.4

func (r Response) Bytes() []byte

Bytes converts Response data structure into bytes array.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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