memory

package module
v0.0.0-...-c0075a2 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: MIT Imports: 4 Imported by: 4 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Memory Cache

cache data in memory implemented by go-cache

Usage

    memCache := NewCache()
    err := memCache.SetString(context.TODO(), key, val, -1)

Notice

Save and Load function just for test because go-cache SaveFile is deprecated.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(memCache *Cache, filePath string) error

Load read cache file from disk file, just for testing

func Save

func Save(memCache *Cache, filePath string) error

Save sync cache file to disk file, just for testing

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache basic memory cache

func NewCache

func NewCache() *Cache

NewCache new memory cache

func (*Cache) Decrease

func (c *Cache) Decrease(ctx context.Context, key string, value int64) (data int64, err error)

func (*Cache) Del

func (c *Cache) Del(ctx context.Context, Key string) error

Del delete key from cache

func (*Cache) Flush

func (c *Cache) Flush(ctx context.Context) error

Flush deletes all items from cache

func (*Cache) GetInt64

func (c *Cache) GetInt64(ctx context.Context, key string) (data int64, exist bool, err error)

GetInt64 get int64 value by key

func (*Cache) GetString

func (c *Cache) GetString(ctx context.Context, key string) (data string, exist bool, err error)

GetString get string value by key

func (*Cache) Increase

func (c *Cache) Increase(ctx context.Context, key string, value int64) (data int64, err error)

func (*Cache) SetInt64

func (c *Cache) SetInt64(ctx context.Context, key string, value int64, ttl time.Duration) error

SetInt64 set int64 value with key and ttl

func (*Cache) SetString

func (c *Cache) SetString(ctx context.Context, key, value string, ttl time.Duration) error

SetString set string value with key and ttl

Jump to

Keyboard shortcuts

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