cache

package
v1.0.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2019 License: MIT Imports: 2 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// LRUAlgorithm ...
	LRUAlgorithm = "lru"
	// LFUAlgorithm ...
	LFUAlgorithm = "lfu"
	// DefaultSize ..
	DefaultSize = 100
	// DefaultExpiryTime ...
	DefaultExpiryTime = time.Second * 10
	// DefaultAlgorithm ...
	DefaultAlgorithm = LRUAlgorithm
)

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

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

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