Documentation ¶
Overview ¶
mcache is a package to provide an in-memory key/value cache:
- thread safe
- expiration
- CAS update
Index ¶
- Variables
- type ExpirationKind
- type MCache
- func (mc MCache) Add(key string, value interface{}, expire time.Duration, kind ExpirationKind) bool
- func (mc MCache) Clear()
- func (mc MCache) Count() int
- func (mc MCache) Delete(key string)
- func (mc MCache) DeleteMulti(keys []string)
- func (mc MCache) Exists(key string) bool
- func (mc MCache) Get(key string) (interface{}, bool)
- func (mc MCache) GetV(key string) (interface{}, int, bool)
- func (mc MCache) Keys() []string
- func (mc MCache) Put(key string, value interface{}, expire time.Duration, kind ExpirationKind)
- func (mc MCache) PutAbs(key string, value interface{}, expire time.Duration)
- func (mc MCache) PutP(key string, value interface{})
- func (mc MCache) PutSlid(key string, value interface{}, expire time.Duration)
- func (mc MCache) Stat() string
- func (mc MCache) Update(key string, value interface{}) bool
- func (mc MCache) UpdateV(key string, version int, value interface{}) bool
Constants ¶
This section is empty.
Variables ¶
View Source
var TickInterval time.Duration = time.Minute
TickInterval is the the interval duration of expiration check
Functions ¶
This section is empty.
Types ¶
type ExpirationKind ¶
type ExpirationKind int
ExpirationKind is the kind of cache entry expiration
const ( // SlidingExpiration means cache entry should be evicted if it has not been accessed in a given span of time. SlidingExpiration ExpirationKind = 0 // AbsoluteExpiration means cache entry should be evicted after a specified duration. AbsoluteExpiration ExpirationKind = 1 )
type MCache ¶
type MCache struct {
// contains filtered or unexported fields
}
MCache is cache in memory
func NewMemoryCache ¶
func (MCache) Add ¶
func (mc MCache) Add(key string, value interface{}, expire time.Duration, kind ExpirationKind) bool
Add insert a cache entry, it return false if key exist
func (MCache) Count ¶
func (mc MCache) Count() int
Count return number of cache entry, maybe include expired
func (MCache) DeleteMulti ¶
func (mc MCache) DeleteMulti(keys []string)
DeleteMulti delete some keys from cache
func (MCache) Put ¶
func (mc MCache) Put(key string, value interface{}, expire time.Duration, kind ExpirationKind)
Put set a cache entry with expire time span and kind
func (MCache) PutP ¶
func (mc MCache) PutP(key string, value interface{})
PutP set a cache entry with very long expiration time
Click to show internal directories.
Click to hide internal directories.