Documentation ¶
Index ¶
- func NewStore() limiter.Store
- func NewStoreWithOptions(options limiter.StoreOptions) limiter.Store
- type Cache
- func (cache *Cache) Clean()
- func (cache *Cache) Delete(key string)
- func (cache *Cache) Get(key string, duration time.Duration) (int64, time.Time)
- func (cache *Cache) Increment(key string, value int64, duration time.Duration) (int64, time.Time)
- func (cache *Cache) Load(key string) (*Counter, bool)
- func (cache *Cache) LoadOrStore(key string, counter *Counter) (*Counter, bool)
- func (cache *Cache) Range(handler func(key string, counter *Counter))
- func (cache *Cache) Reset(key string, duration time.Duration) (int64, time.Time)
- func (cache *Cache) Store(key string, counter *Counter)
- type CacheWrapper
- type Counter
- type Store
- func (store *Store) Get(ctx context.Context, key string, rate limiter.Rate) (limiter.Context, error)
- func (store *Store) Peek(ctx context.Context, key string, rate limiter.Rate) (limiter.Context, error)
- func (store *Store) Reset(ctx context.Context, key string, rate limiter.Rate) (limiter.Context, error)
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) Increment ¶
Increment increments given value on key. If key is undefined or expired, it will create it.
func (*Cache) Load ¶ added in v3.8.0
Load returns the counter stored in the map for a key, or nil if no counter is present. The ok result indicates whether counter was found in the map.
func (*Cache) LoadOrStore ¶ added in v3.8.0
LoadOrStore returns the existing counter for the key if present. Otherwise, it stores and returns the given counter. The loaded result is true if the counter was loaded, false if stored.
func (*Cache) Range ¶ added in v3.8.0
Range calls handler sequentially for each key and value present in the cache. If handler returns false, range stops the iteration.
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 {
// contains filtered or unexported fields
}
Counter is a simple counter with an expiration.
func (*Counter) Expiration ¶
Expiration returns the counter expiration.
func (*Counter) Increment ¶ added in v3.8.0
Increment increments given value on this counter. If the counter is expired, it will use the given expiration. It returns its current value and expiration.
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.