models

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 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

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

func (item *Item) Expired() bool

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

func (*Item) SetSize added in v0.1.0

func (item *Item) SetSize() error

SetSize stores the size of the Item in bytes

func (*Item) SizeKB added in v0.1.0

func (item *Item) SizeKB() float64

SizeKB returns the size of the Item in kilobytes

func (*Item) SizeMB added in v0.1.0

func (item *Item) SizeMB() float64

SizeMB returns the size of the Item in megabytes

func (*Item) Touch

func (item *Item) Touch()

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

func (*Item) Valid

func (item *Item) Valid() error

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

Jump to

Keyboard shortcuts

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