Documentation ¶
Index ¶
- Variables
- type Cacher
- type LocalCache
- func (m *LocalCache) Delete(_ context.Context, key string)
- func (m *LocalCache) Exist(_ context.Context, key string) bool
- func (m *LocalCache) Get(ctx context.Context, key string) ([]byte, error)
- func (m *LocalCache) Separator() string
- func (m *LocalCache) Set(_ context.Context, key string, value []byte, ttl time.Duration) error
Constants ¶
This section is empty.
Variables ¶
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
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