types

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ItemPool is a pool of Item values.
	ItemPool = sync.Pool{
		New: func() any {
			return &Item{}
		},
	}
)

Functions

This section is empty.

Types

type Item added in v0.1.3

type Item struct {
	Key         string        // key of the item
	Value       any           // Value of the item
	Size        int64         // Size of the item, in bytes
	Expiration  time.Duration // Expiration duration of the item
	LastAccess  time.Time     // LastAccess time of the item
	AccessCount uint          // AccessCount of times the item has been accessed
}

Item is a struct that represents an item in the cache. It has a key, value, expiration duration, and a last access time field.

func (*Item) Expired added in v0.1.3

func (item *Item) Expired() bool

Expired returns true if the item has expired, false otherwise.

func (*Item) SetSize added in v0.1.3

func (item *Item) SetSize() error

SetSize stores the size of the Item in bytes

func (*Item) SizeKB added in v0.1.3

func (item *Item) SizeKB() float64

SizeKB returns the size of the Item in kilobytes

func (*Item) SizeMB added in v0.1.3

func (item *Item) SizeMB() float64

SizeMB returns the size of the Item in megabytes

func (*Item) Touch added in v0.1.3

func (item *Item) Touch()

Touch updates the last access time of the item and increments the access count.

func (*Item) Valid added in v0.1.3

func (item *Item) Valid() error

Valid returns an error if the item is invalid, nil otherwise.

type SortingField

type SortingField string

SortingField is a type that represents the field to sort the cache items by.

const (
	SortByKey         SortingField = "Key"         // Sort by the key of the cache item
	SortBySize        SortingField = "Size"        // Sort by the size in bytes of the cache item
	SortByLastAccess  SortingField = "LastAccess"  // Sort by the last access time of the cache item
	SortByAccessCount SortingField = "AccessCount" // Sort by the number of times the cache item has been accessed
	SortByExpiration  SortingField = "Expiration"  // Sort by the expiration duration of the cache item
)

Constants for the different fields that the cache items can be sorted by.

func (SortingField) String

func (f SortingField) String() string

String returns the string representation of the SortingField.

type Stat added in v0.0.4

type Stat string

Stat is a type that represents a different stat values that can be collected by the stats collector.

const (
	// StatIncr represent a stat that should be incremented
	StatIncr Stat = "incr"
	// StatDecr represent a stat that should be decremented
	StatDecr Stat = "decr"
	// StatTiming represent a stat that represents the time it takes for an event to occur
	StatTiming Stat = "timing"
	// StatGauge represent a stat that represents the current value of a statistic
	StatGauge Stat = "gauge"
	// StatHistogram represent a stat that represents the statistical distribution of a set of values
	StatHistogram Stat = "histogram"
)

func (Stat) String added in v0.0.4

func (s Stat) String() string

String returns the string representation of a Stat.

Jump to

Keyboard shortcuts

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