cache

package module
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: Apache-2.0 Imports: 5 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNilCache = errors.New("cache does not exist")

Functions

This section is empty.

Types

type Cacher

type Cacher interface {
	// Set the Cache key and value.
	Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
	// Get the Value by Key. Returns tower.ErrNilCache if not found or ttl has passed.
	Get(ctx context.Context, key string) ([]byte, error)
	// Delete cache by key.
	Delete(ctx context.Context, key string)
	// Exist Checks if Key exist in cache.
	Exist(ctx context.Context, key string) bool
	// Separator Returns Accepted separator value for the Cacher implementor.
	Separator() string
}

type LocalCache added in v0.5.2

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

func NewLocalCache added in v0.5.2

func NewLocalCache() *LocalCache

NewLocalCache creates a RAM based cache.

This cache is not persistent and will be lost on application restart.

This cache does not support distributed caching mechanism, and is not safe for multiple application that uses the same key for handling rate limits

(e.g. Discord enforced 1 second limit between messages with the same token, if the token is shared between services, and you use this local cache for all your machines, your token may be banned by Discord for over limit since the services cannot know the state of current rate limit, and thus just assume everything is safe to be sent).

Use this cache for tests or when you know that you will not have multiple application instances.

func (*LocalCache) Delete added in v0.5.2

func (m *LocalCache) Delete(_ context.Context, key string)

Delete key from cache.

func (*LocalCache) Exist added in v0.5.2

func (m *LocalCache) Exist(_ context.Context, key string) bool

Exist Checks if Key exist in cache.

func (*LocalCache) Get added in v0.5.2

func (m *LocalCache) Get(ctx context.Context, key string) ([]byte, error)

Get the Value by Key. Returns tower.ErrNilCache if not found or ttl has passed.

func (*LocalCache) Separator added in v0.5.2

func (m *LocalCache) Separator() string

func (*LocalCache) Set added in v0.5.2

func (m *LocalCache) Set(_ context.Context, key string, value []byte, ttl time.Duration) error

Set Sets the Cache key and value.

Directories

Path Synopsis
goredis module

Jump to

Keyboard shortcuts

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