cache

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 2 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// Byte ...
	Byte uint64 = 1
	// KB ...
	KB = Byte * 1024
	// MB ...
	MB = KB * 1024
	// LRUAlgorithm ...
	LRUAlgorithm = "lru"
	// LFUAlgorithm ...
	LFUAlgorithm = "lfu"
	// DefaultSize ..
	DefaultSize = 100
	// DefaultExpiryTime ...
	DefaultExpiryTime = time.Second * 10
	// DefaultAlgorithm ...
	DefaultAlgorithm = LRUAlgorithm
	// DefaultMaxMemory ...
	DefaultMaxMemory = 10 * MB
)

Variables

View Source
var (
	// ErrMissed ...
	ErrMissed = errors.New("Cache item's missing")
)

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Set(key string, value interface{}) error
	Get(key string) (val interface{}, err error)
	Delete(key string) (err error)
	GetKeys() (keys []string, err error)
	ClearCache() (err error)
}

Cache represent the public API that will available used by user

type Document

type Document struct {
	Key        string
	Value      interface{}
	StoredTime int64 // timestamp
}

Document represent the Document structure stored in the cache

type Option

type Option struct {
	AlgorithmType string        // represent the algorithm type
	ExpiryTime    time.Duration // represent the expiry time of each stored item
	MaxSizeItem   uint64        // Max size of item for eviction
	MaxMemory     uint64        // Max Memory of item stored for eviction
}

Option used for Cache configuration

func (*Option) SetAlgorithm

func (o *Option) SetAlgorithm(algorithm string) *Option

SetAlgorithm will set the algorithm value

func (*Option) SetExpiryTime

func (o *Option) SetExpiryTime(expiry time.Duration) *Option

SetExpiryTime will set the expiry time

func (*Option) SetMaxMemory

func (o *Option) SetMaxMemory(memory uint64) *Option

SetMaxMemory will set the maximum memory will used for cache

func (*Option) SetMaxSizeItem

func (o *Option) SetMaxSizeItem(size uint64) *Option

SetMaxSizeItem will set the maximum size of item in cache

Jump to

Keyboard shortcuts

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