mcache

package module
v0.0.0-...-7835ee8 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2016 License: Apache-2.0 Imports: 5 Imported by: 0

README

mcache Build Status Coverage Status GoDoc

Warning

This package is deprecated.

Credit

Based on the source code from https://github.com/stephanos/mcache.

License

Apache License 2.0 (see LICENSE).

Documentation

Overview

mcache is a package to provide an in-memory key/value cache:

  • thread safe
  • expiration
  • CAS update

Index

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 NewMemoryCache(expire bool) *MCache

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) Clear

func (mc MCache) Clear()

Clear deletes everything from the cache

func (MCache) Count

func (mc MCache) Count() int

Count return number of cache entry, maybe include expired

func (MCache) Delete

func (mc MCache) Delete(key string)

Delete delete cache entry from the cache

func (MCache) DeleteMulti

func (mc MCache) DeleteMulti(keys []string)

DeleteMulti delete some keys from cache

func (MCache) Exists

func (mc MCache) Exists(key string) bool

Exists return whether the key exist

func (MCache) Get

func (mc MCache) Get(key string) (interface{}, bool)

Get return a cached value, it return false if key doesn't exist

func (MCache) GetV

func (mc MCache) GetV(key string) (interface{}, int, bool)

GetV return cached value and it's version

func (MCache) Keys

func (mc MCache) Keys() []string

Keys return all cache keys

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) PutAbs

func (mc MCache) PutAbs(key string, value interface{}, expire time.Duration)

PutAbs set a cache entry with AbsoluteExpiration

func (MCache) PutP

func (mc MCache) PutP(key string, value interface{})

PutP set a cache entry with very long expiration time

func (MCache) PutSlid

func (mc MCache) PutSlid(key string, value interface{}, expire time.Duration)

PutSlid set a cache entry with SlidingExpiration

func (MCache) Stat

func (mc MCache) Stat() string

Stat return MCache stat information

func (MCache) Update

func (mc MCache) Update(key string, value interface{}) bool

Update update cache entry, it return false if key doesn't exist

func (MCache) UpdateV

func (mc MCache) UpdateV(key string, version int, value interface{}) bool

UpdateV update cache entry when version match

Jump to

Keyboard shortcuts

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