Import path:
gitlab.soludian.com/soludian/fountain/libs/cache/memory_cache
memory_cache
import "gitlab.soludian.com/soludian/fountain/libs/cache/memory_cache"Index
- Constants
- Variables
- func NewMemoryCache() cache.Cache
- type Cache
- func (rc *Cache) ClearAll(context.Context) error
- func (rc *Cache) Close() error
- func (rc *Cache) Decr(key string) (int64, error)
- func (rc *Cache) Delete(key string) error
- func (rc *Cache) Get(key string) ([]byte, error)
- func (rc *Cache) GetDefaultConfig() string
- func (rc *Cache) GetMulti(keys []string) ([][]byte, error)
- func (rc *Cache) Has(key string) bool
- func (rc *Cache) Incr(key string) (int64, error)
- func (rc *Cache) Peek(key string) (any, error)
- func (rc *Cache) PeekMulti(keys []string) ([]any, error)
- func (rc *Cache) Put(key string, val any, ttl time.Duration) error
- func (rc *Cache) PutMulti(values map[string]any, ttl time.Duration) error
- func (rc *Cache) Reset() error
- func (rc *Cache) Set(key string, val []byte, ttl time.Duration) error
- func (rc *Cache) SetMulti(values map[string][]byte, ttl time.Duration) error
- func (rc *Cache) SetName(name string)
- func (rc *Cache) StartAndGC(configs ...string) error
Constants
const DefaultConfig = `{"interval": 5}`const KPackageName = "memory_cache"Variables
DefaultEvery sets a timer for how often to recycle the expired cache items in memory (in seconds)
var DefaultEvery = 60 // 1 minutefunc NewMemoryCache
func NewMemoryCache() cache.CacheNewMemoryCache returns a new MemoryCache.
type Cache
MemoryCache is a memory cache adapter. Contains a RW locker for safe map storage.
type Cache struct {
sync.RWMutex
Every int // run an expiration check Every clock time
// contains filtered or unexported fields
}func (*Cache) ClearAll
func (rc *Cache) ClearAll(context.Context) errorClearAll deletes all cache in memory.
func (*Cache) Close
func (rc *Cache) Close() errorClose the cache
func (*Cache) Decr
func (rc *Cache) Decr(key string) (int64, error)Decr decreases counter in memory.
func (*Cache) Delete
func (rc *Cache) Delete(key string) errorDelete cache in memory. If the key is not found, it will not return error
func (*Cache) Get
func (rc *Cache) Get(key string) ([]byte, error)Get gets a key's value from memcache.
func (*Cache) GetDefaultConfig
func (rc *Cache) GetDefaultConfig() stringfunc (*Cache) GetMulti
func (rc *Cache) GetMulti(keys []string) ([][]byte, error)GetMulti gets one or keys values from ssdb.
func (*Cache) Has
func (rc *Cache) Has(key string) boolHas checks if cache exists in memory.
func (*Cache) Incr
func (rc *Cache) Incr(key string) (int64, error)Incr increases cache counter in memory. Supports int,int32,int64,uint,uint32,uint64.
func (*Cache) Peek
func (rc *Cache) Peek(key string) (any, error)Peek returns cache from memory. If non-existent or expired, return nil.
func (*Cache) PeekMulti
func (rc *Cache) PeekMulti(keys []string) ([]any, error)PeekMulti gets caches from memory. If non-existent or expired, return nil.
func (*Cache) Put
func (rc *Cache) Put(key string, val any, ttl time.Duration) errorPut puts cache into memory. If lifespan is 0, it will never overwrite this value unless restarted
func (*Cache) PutMulti
func (rc *Cache) PutMulti(values map[string]any, ttl time.Duration) errorfunc (*Cache) Reset
func (rc *Cache) Reset() errorfunc (*Cache) Set
func (rc *Cache) Set(key string, val []byte, ttl time.Duration) errorfunc (*Cache) SetMulti
func (rc *Cache) SetMulti(values map[string][]byte, ttl time.Duration) errorfunc (*Cache) SetName
func (rc *Cache) SetName(name string)func (*Cache) StartAndGC
func (rc *Cache) StartAndGC(configs ...string) errorStartAndGC starts memory cache. Checks expiration in every clock time.
Generated by gomarkdoc