memory

package
v2.2.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStore

func NewStore() limiter.Store

NewStore creates a new instance of memory store with defaults.

func NewStoreWithOptions

func NewStoreWithOptions(options limiter.StoreOptions) limiter.Store

NewStoreWithOptions creates a new instance of memory store with options.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache contains a collection of counters.

func (*Cache) Clean

func (cache *Cache) Clean()

Clean will deleted any expired keys.

func (*Cache) Get

func (cache *Cache) Get(key string, duration time.Duration) (int64, time.Time)

Get returns key's value and expiration.

func (*Cache) Increment

func (cache *Cache) Increment(key string, value int64, duration time.Duration) (int64, time.Time)

Increment increments given value on key. If key is undefined or expired, it will create it.

type CacheWrapper

type CacheWrapper struct {
	*Cache
}

CacheWrapper is used to ensure that the underlying cleaner goroutine used to clean expired keys will not prevent Cache from being garbage collected.

func NewCache

func NewCache(cleanInterval time.Duration) *CacheWrapper

NewCache returns a new cache.

type Counter

type Counter struct {
	Value      int64
	Expiration int64
}

Counter is a simple counter with an optional expiration.

func (Counter) Expired

func (counter Counter) Expired() bool

Expired returns true if the counter has expired.

type Store

type Store struct {
	// Prefix used for the key.
	Prefix string
	// contains filtered or unexported fields
}

Store is the in-memory store.

func (*Store) Get

func (store *Store) Get(ctx context.Context, key string, rate limiter.Rate) (limiter.Context, error)

Get returns the limit for given identifier.

func (*Store) Peek

func (store *Store) Peek(ctx context.Context, key string, rate limiter.Rate) (limiter.Context, error)

Peek returns the limit for given identifier, without modification on current values.

Jump to

Keyboard shortcuts

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