localcache

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2018 License: Apache-2.0 Imports: 3 Imported by: 0

README

localcache is an in-memory cache store.

GoDoc

Documentation

Index

Constants

View Source
const (
	// ExpireDuration indicate key has already expired, so set to -1.
	ExpireDuration = time.Duration(-1)
)

Variables

View Source
var (
	// ErrTypeMismatch is a err indicate GetXXX func is not match with the real value with key.
	ErrTypeMismatch = errors.New("err: type mismatch")
	// ErrNoSuchKey indicate key not exist.
	ErrNoSuchKey = errors.New("err: no such key")
	// ErrKeyExpired indicate key has expired, but has't remove from cache.
	ErrKeyExpired = errors.New("err: key already expired")
	// ErrDuplicateEvictedFunc will panic.
	ErrDuplicateEvictedFunc = errors.New("err: re-set evicted function")
)

Functions

This section is empty.

Types

type CacheStat

type CacheStat struct {
	Entries int64
	Expired int64
}

CacheStat store cache stats.

type Entry

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

Entry is a container present data with expire info.

type LocalCache

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

LocalCache is an in-memory struct store key-value pairs.

func NewLocalCache

func NewLocalCache(defaultExpiration int64) *LocalCache

NewLocalCache return a empty LocalCache.

func (*LocalCache) Expire

func (c *LocalCache) Expire(key string) (err error)

Expire to expire a key immediately, ignore the default and left expiration.

func (*LocalCache) Flush

func (c *LocalCache) Flush()

Flush will reset all data in cache, but stats will be keeped.

func (*LocalCache) Get

func (c *LocalCache) Get(key string) (v interface{}, err error)

Get get the value associated by a key or an error.

func (*LocalCache) GetBool

func (c *LocalCache) GetBool(key string) (v bool, err error)

GetBool get bool value associated by key or an error.

func (*LocalCache) GetByte

func (c *LocalCache) GetByte(key string) (v byte, err error)

GetByte get byte value associated by key or an error.

func (*LocalCache) GetEntry

func (c *LocalCache) GetEntry(key string) (v *ResponseEntry, err error)

GetEntry get a response entry which explain usability of the value or an error.

func (*LocalCache) GetFloat64

func (c *LocalCache) GetFloat64(key string) (v float64, err error)

GetFloat64 get float64 value associated by key or an error.

func (*LocalCache) GetInt64

func (c *LocalCache) GetInt64(key string) (v int64, err error)

GetInt64 get int64 value associated by key or an error.

func (*LocalCache) GetKeysEntry

func (c *LocalCache) GetKeysEntry(keys []string) (v map[string]*ResponseEntry)

GetKeysEntry get a map of Key-ResponseEntry which explain usability of the value.

func (*LocalCache) GetRune

func (c *LocalCache) GetRune(key string) (v rune, err error)

GetRune get rune value associated by key or an error.

func (*LocalCache) GetString

func (c *LocalCache) GetString(key string) (v string, err error)

GetString get string value associated by key or an error.

func (*LocalCache) GetUint64

func (c *LocalCache) GetUint64(key string) (v uint64, err error)

GetUint64 get uint64 value associated by key or an error.

func (*LocalCache) GetWithExpire

func (c *LocalCache) GetWithExpire(key string) (v interface{}, expire time.Duration, err error)

GetWithExpire get the value and left life associated by a key or an error.

func (*LocalCache) Reset

func (c *LocalCache) Reset()

Reset will reset both data and stats.

func (*LocalCache) Set

func (c *LocalCache) Set(key string, value interface{})

Set set key-value with default expiration.

func (*LocalCache) SetEvictedFunc

func (c *LocalCache) SetEvictedFunc(f func(string, *Entry))

SetEvictedFunc set evicted func, this must be called no more once.

func (*LocalCache) SetWithExpire

func (c *LocalCache) SetWithExpire(key string, value interface{}, duration int64)

SetWithExpire set key-value with user setup expiration.

func (*LocalCache) Stats

func (c *LocalCache) Stats() *CacheStat

Stats return cache stats.

type ResponseEntry

type ResponseEntry struct {
	Valid bool
	Value interface{}
}

ResponseEntry is a wrapper of response data.

Jump to

Keyboard shortcuts

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