Documentation ¶
Overview ¶
Package memstore offers an in-memory store implementation for throttled.
Index ¶
- func NewCtx(maxKeys int) (throttled.GCRAStoreCtx, error)
- type MemStore
- func (ms *MemStore) CompareAndSwapWithTTL(key string, old, new int64, _ time.Duration) (bool, error)
- func (ms *MemStore) GetWithTime(key string) (int64, time.Time, error)
- func (ms *MemStore) SetIfNotExistsWithTTL(key string, value int64, _ time.Duration) (bool, error)
- func (ms *MemStore) SetTimeNow(timeNow func() time.Time)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type MemStore ¶
MemStore is an in-memory store implementation for throttled. It supports evicting the least recently used keys to control memory usage. It is stored in memory in the current process and thus doesn't share state with other rate limiters.
func New ¶
New initializes a Store. If maxKeys > 0, the number of different keys is restricted to the specified amount. In this case, it uses an LRU algorithm to evict older keys to make room for newer ones. If maxKeys <= 0, there is no limit on the number of keys, which may use an unbounded amount of memory.
func (*MemStore) CompareAndSwapWithTTL ¶
func (ms *MemStore) CompareAndSwapWithTTL(key string, old, new int64, _ time.Duration) (bool, error)
CompareAndSwapWithTTL atomically compares the value at key to the old value. If it matches, it sets it to the new value and returns true. Otherwise, it returns false. If the key does not exist in the store, it returns false with no error. It ignores the ttl.
func (*MemStore) GetWithTime ¶
GetWithTime returns the value of the key if it is in the store or -1 if it does not exist. It also returns the current local time on the machine.
func (*MemStore) SetIfNotExistsWithTTL ¶
SetIfNotExistsWithTTL sets the value of key only if it is not already set in the store it returns whether a new value was set. It ignores the ttl.
func (*MemStore) SetTimeNow ¶ added in v2.6.0
SetTimeNow makes this store use the given function instead of time.Now(). This is useful for unit tests that use a simulated wallclock.