memstore

package
v2.2.5+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2020 License: BSD-3-Clause Imports: 4 Imported by: 0

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

type MemStore struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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

func New(maxKeys int) (*MemStore, error)

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

func (ms *MemStore) GetWithTime(key string) (int64, time.Time, error)

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

func (ms *MemStore) SetIfNotExistsWithTTL(key string, value int64, _ time.Duration) (bool, error)

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.

Jump to

Keyboard shortcuts

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