caches

package
v0.3.1-alpha Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NeverDie means value.alive() returns true forever.
	NeverDie = 0
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is a struct with caching functions.

func NewCache

func NewCache() *Cache

NewCache returns a new Cache holder with default options.

func NewCacheWith

func NewCacheWith(options Options) *Cache

NewCacheWith returns a new Cache holder with given options.

func (*Cache) AutoDump

func (c *Cache) AutoDump()

AutoDump starts a goroutine and runs the dump task at fixed duration.

func (*Cache) AutoGc

func (c *Cache) AutoGc()

AutoGc starts a goroutine and runs the gc task at fixed duration.

func (*Cache) Delete

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

Delete deletes the specified key and value.

func (*Cache) Get

func (c *Cache) Get(key string) ([]byte, bool)

Get returns the value of specified key.

func (*Cache) Set

func (c *Cache) Set(key string, value []byte) error

Set sets an entry of specified key and value.

func (*Cache) SetWithTTL

func (c *Cache) SetWithTTL(key string, value []byte, ttl int64) error

SetWithTTL sets an entry of specified key and value which has ttl.

func (*Cache) Status

func (c *Cache) Status() Status

Status returns the status of cache.

type Options

type Options struct {

	// MaxEntrySize is the max memory size that entries can use.
	// The unit is GB.
	MaxEntrySize int

	// MaxGcCount is the max count of entries that gc will clean.
	MaxGcCount int

	// GcDuration is the duration between two gc tasks.
	// The unit is Minute.
	GcDuration int

	// DumpFile is the file used to dump the cache.
	DumpFile string

	// DumpDuration is the duration between two dump tasks.
	// The unit is Minute.
	DumpDuration int

	// MapSizeOfSegment is the map size of segment.
	MapSizeOfSegment int

	// SegmentSize is the number of segment in a cache.
	// This value should be the pow of 2 for precision.
	SegmentSize int

	// CasSleepTime is the time of sleep in one cas step.
	// The unit is Microsecond.
	CasSleepTime int
}

Options is the struct of options.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns a default options.

type Status

type Status struct {

	// Count is how many entries stored in cache.
	Count int `json:"count"`

	// KeySize is the size of key.
	KeySize int64 `json:"keySize"`

	// ValueSize is the size of value.
	ValueSize int64 `json:"valueSize"`
}

Status is the status of cache.

func NewStatus

func NewStatus() *Status

NewStatus returns a new status holder.

Jump to

Keyboard shortcuts

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