Documentation ¶
Index ¶
- Variables
- type LocalLock
- func (m *LocalLock) Delete(_ context.Context, key string)
- func (m *LocalLock) Exist(_ context.Context, key string) bool
- func (m *LocalLock) Get(ctx context.Context, key string) ([]byte, error)
- func (m *LocalLock) Separator() string
- func (m *LocalLock) Set(_ context.Context, key string, value []byte, ttl time.Duration) error
- type Locker
Constants ¶
This section is empty.
Variables ¶
var ErrNil = errors.New("value does not exist")
Functions ¶
This section is empty.
Types ¶
type LocalLock ¶
type LocalLock struct {
// contains filtered or unexported fields
}
func NewLocalLock ¶
func NewLocalLock() *LocalLock
NewLocalLock 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.
type Locker ¶
type Locker interface { // Set the key and value. Set(ctx context.Context, key string, value []byte, ttl time.Duration) error // Get the Value by Key. Get(ctx context.Context, key string) ([]byte, error) // Delete value 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 Lock implementor. Separator() string }