Documentation
¶
Index ¶
- Constants
- Variables
- type CacheStat
- type Entry
- type LocalCache
- func (c *LocalCache) Expire(key string) (err error)
- func (c *LocalCache) Flush()
- func (c *LocalCache) Get(key string) (v interface{}, err error)
- func (c *LocalCache) GetBool(key string) (v bool, err error)
- func (c *LocalCache) GetByte(key string) (v byte, err error)
- func (c *LocalCache) GetEntry(key string) (v *ResponseEntry, err error)
- func (c *LocalCache) GetFloat64(key string) (v float64, err error)
- func (c *LocalCache) GetInt64(key string) (v int64, err error)
- func (c *LocalCache) GetKeysEntry(keys []string) (v map[string]*ResponseEntry)
- func (c *LocalCache) GetRune(key string) (v rune, err error)
- func (c *LocalCache) GetString(key string) (v string, err error)
- func (c *LocalCache) GetUint64(key string) (v uint64, err error)
- func (c *LocalCache) GetWithExpire(key string) (v interface{}, expire time.Duration, err error)
- func (c *LocalCache) Reset()
- func (c *LocalCache) Set(key string, value interface{})
- func (c *LocalCache) SetEvictedFunc(f func(string, *Entry))
- func (c *LocalCache) SetWithExpire(key string, value interface{}, duration int64)
- func (c *LocalCache) Stats() *CacheStat
- type ResponseEntry
Constants ¶
const ( // ExpireDuration indicate key has already expired, so set to -1. ExpireDuration = time.Duration(-1) )
Variables ¶
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 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) 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.
type ResponseEntry ¶
type ResponseEntry struct { Valid bool Value interface{} }
ResponseEntry is a wrapper of response data.