Skip to content

Import path: gitlab.soludian.com/soludian/fountain/libs/cache/memory_cache

memory_cache

go
import "gitlab.soludian.com/soludian/fountain/libs/cache/memory_cache"

Index

Constants

go
const DefaultConfig = `{"interval": 5}`

go
const KPackageName = "memory_cache"

Variables

DefaultEvery sets a timer for how often to recycle the expired cache items in memory (in seconds)

go
var DefaultEvery = 60 // 1 minute

func NewMemoryCache

go
func NewMemoryCache() cache.Cache

NewMemoryCache returns a new MemoryCache.

type Cache

MemoryCache is a memory cache adapter. Contains a RW locker for safe map storage.

go
type Cache struct {
    sync.RWMutex

    Every int // run an expiration check Every clock time
    // contains filtered or unexported fields
}

func (*Cache) ClearAll

go
func (rc *Cache) ClearAll(context.Context) error

ClearAll deletes all cache in memory.

func (*Cache) Close

go
func (rc *Cache) Close() error

Close the cache

func (*Cache) Decr

go
func (rc *Cache) Decr(key string) (int64, error)

Decr decreases counter in memory.

func (*Cache) Delete

go
func (rc *Cache) Delete(key string) error

Delete cache in memory. If the key is not found, it will not return error

func (*Cache) Get

go
func (rc *Cache) Get(key string) ([]byte, error)

Get gets a key's value from memcache.

func (*Cache) GetDefaultConfig

go
func (rc *Cache) GetDefaultConfig() string

func (*Cache) GetMulti

go
func (rc *Cache) GetMulti(keys []string) ([][]byte, error)

GetMulti gets one or keys values from ssdb.

func (*Cache) Has

go
func (rc *Cache) Has(key string) bool

Has checks if cache exists in memory.

func (*Cache) Incr

go
func (rc *Cache) Incr(key string) (int64, error)

Incr increases cache counter in memory. Supports int,int32,int64,uint,uint32,uint64.

func (*Cache) Peek

go
func (rc *Cache) Peek(key string) (any, error)

Peek returns cache from memory. If non-existent or expired, return nil.

func (*Cache) PeekMulti

go
func (rc *Cache) PeekMulti(keys []string) ([]any, error)

PeekMulti gets caches from memory. If non-existent or expired, return nil.

func (*Cache) Put

go
func (rc *Cache) Put(key string, val any, ttl time.Duration) error

Put puts cache into memory. If lifespan is 0, it will never overwrite this value unless restarted

func (*Cache) PutMulti

go
func (rc *Cache) PutMulti(values map[string]any, ttl time.Duration) error

func (*Cache) Reset

go
func (rc *Cache) Reset() error

func (*Cache) Set

go
func (rc *Cache) Set(key string, val []byte, ttl time.Duration) error

func (*Cache) SetMulti

go
func (rc *Cache) SetMulti(values map[string][]byte, ttl time.Duration) error

func (*Cache) SetName

go
func (rc *Cache) SetName(name string)

func (*Cache) StartAndGC

go
func (rc *Cache) StartAndGC(configs ...string) error

StartAndGC starts memory cache. Checks expiration in every clock time.

Generated by gomarkdoc