Documentation ¶
Overview ¶
Package memstore offers an in-memory store implementation for throttled.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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.