memory

package
v5.0.0-...-03972fd Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Options
	// contains filtered or unexported fields
}

func New

func New(options Options) *Cache

func (*Cache) Clear

func (c *Cache) Clear() error

This isn't thread safe. It's meant to be called from non-concurrent tests

func (*Cache) Decrease

func (c *Cache) Decrease(key string) error

Decrease cached int value by key, as a counter.

func (*Cache) Delete

func (c *Cache) Delete(key string) error

Remove the item from the cache.

func (*Cache) Get

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

Get an item from the cache. Returns nil if the item wasn't found or expired.

func (*Cache) GetMulti

func (c *Cache) GetMulti(dict map[string]interface{}) (notFound []string, err error)

Get multiple values from cache.

func (*Cache) Increase

func (c *Cache) Increase(key string) error

Increase cached int value by key, as a counter.

func (*Cache) IsExists

func (c *Cache) IsExists(key string) (bool, error)

Check if value exists or not.

func (*Cache) Set

func (c *Cache) Set(key string, value interface{}, duration time.Duration) error

Set the value in the cache for the specified duration

func (*Cache) Stop

func (c *Cache) Stop()

Stops the background worker. Operations performed on the cache after Stop is called are likely to panic

type Options

type Options struct {
	// Max size of cache
	MaxSize int64
	// Bucket count (2 ^ n). Default 4
	Buckets uint8
	// The number of items to prune when memory is low. Default 500
	ItemsToPrune uint32
	// The size of the queue for items which should be deleted. If the queue fills
	// up, calls to Delete() will block. Default 1024
	DeleteBuffer uint32
	// The size of the queue for items which should be promotes. If the queue fills
	// up, calls to Get/Set/GetMulti/IsExists() will block. Default 1024
	PromoteBuffer uint32
	// Give a large cache with a high read / write ratio, it's usually unnecessary
	// to promote an item on every Get. GetsPerPromote specifies the number of Gets
	// a key must have before being promoted. Default 3
	GetsPerPromote int32
}

type Sized

type Sized interface {
	Size() int64
}

Jump to

Keyboard shortcuts

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