inmemory

package
v0.0.0-...-8b3890d Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2017 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CleanupNone means no cleanup
	CleanupNone CleanupMechanism = iota
	// CleanupCustomFunc calls the set custom function to cleanup the memory
	CleanupCustomFunc = iota
	// CleanupHeapBasedLRU checks the current HeapAlloc, and if it's higher
	// than the CleanupHeapTarget, CleanupPercent% of the least recently used
	// items will be deleted
	CleanupHeapBasedLRU = iota
	// CleanupNumberBasedLRU checks the current number of items, and if it's
	// higher than the CleanupNumberOfItemsTarget, the least recently used
	// items will be deleted so the number of items became (nearly) equal to
	// CleanupNumberOfItemsTarget
	CleanupNumberBasedLRU = iota
)

Variables

View Source
var (
	ErrSmallDuration = errors.New("less than 5 seconds isn't supported by this engine")
)

Functions

func ExpireRevisitFunc

func ExpireRevisitFunc(cache hafezieh.Cache, key string, item *InMemItem)

func NewMemoryCache

func NewMemoryCache(config *InMemoryCacheConfig) (hafezieh.Cache, error)

Types

type CleanupFunc

type CleanupFunc func(*InMemoryCache)

type CleanupMechanism

type CleanupMechanism uint8

type InMemItem

type InMemItem struct {
	Item       interface{}
	CreatedAt  time.Time
	LastAccess time.Time
	Hits       uint
	// contains filtered or unexported fields
}

type InMemKey

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

type InMemoryCache

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

func (*InMemoryCache) Close

func (c *InMemoryCache) Close() error

func (*InMemoryCache) Del

func (c *InMemoryCache) Del(key string) error

func (*InMemoryCache) Get

func (c *InMemoryCache) Get(key string) (interface{}, error)

func (*InMemoryCache) Set

func (c *InMemoryCache) Set(key string, x interface{}, revisitDuration time.Duration) error

type InMemoryCacheConfig

type InMemoryCacheConfig struct {
	RevisitDefaultDuration time.Duration `mapstructure:"revisit-default-duration"`
	RevisitNumberOfWorkers int           `mapstructure:"revisit-number-of-workers"`
	RevisitClock           time.Duration `mapstructure:"revisit-clock"`
	RevisitFunc            RevisitFunc

	Cleanup *InMemoryCleanupConfig `mapstructure:"cleanup"`
}

type InMemoryCleanupConfig

type InMemoryCleanupConfig struct {
	Mechanism           CleanupMechanism `mapstructure:"mechanism"`
	Clock               time.Duration    `mapstructure:"clock"`
	HeapTarget          uint64           `mapstructure:"heap-target"`
	NumberOfItemsTarget uint64           `mapstructure:"number-target"`
	Percent             float64          `mapstructure:"percent"`
	CustomFunc          CleanupFunc
}

type RevisitFunc

type RevisitFunc func(cache hafezieh.Cache, key string, item *InMemItem)

Jump to

Keyboard shortcuts

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