Documentation
¶
Overview ¶
Package memory provides an in-process limiter backend.
It implements the same token bucket semantics as the redis backend and is intended for single-process scenarios, tests and local degradation. Buckets are kept in a sharded map and expired buckets are evicted periodically.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter is an in-process token bucket limiter for one scene.
It is stateless with respect to dimension keys: the same Limiter can be shared by concurrent callers and different keys.
type Maker ¶
type Maker struct {
// contains filtered or unexported fields
}
Maker is a memory limiter maker.
func NewMaker ¶
NewMaker creates a memory limiter maker and starts the expired bucket cleanup.
A cleanup interval of zero or less is clamped to the default of one minute. The cleanup goroutine stops when Close is called.
func (*Maker) Make ¶
Make creates a limiter for the named scene and rule.
The name identifies the scene and must be stable for the lifetime of the maker. A scene keeps the rule it was created with, so creating it again with the same normalized rule reuses the existing bucket state, while a different rule reports errors.ErrConflictLimiterRule.
type Option ¶
type Option func(o *options)
Option configures the memory limiter maker.
func WithCleanupInterval ¶
WithCleanupInterval sets the interval of the expired bucket cleanup. A value of zero or less is clamped to the default of one minute.
func WithPrefix ¶
WithPrefix sets the key prefix. The final key is prefix + ":" + name + ":" + key; an empty prefix disables the prefix.