Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrCleanupFailure = errors.New("at least one error occurred at cleanup") ErrMissingAlgorithm = errors.New("nil LimiterAlgorithm was passed to constructor") )
Functions ¶
func NewLimiterStore ¶
func NewLimiterStore(ctx context.Context, alg rate.LimiterAlgorithm, cleanupInterval time.Duration, opts ...Option) (rate.LimiterStore, error)
NewLimiterStore returns a rate.LimiterStore which stores keys in memory using sync.Map for thread safety. It'll create a single goroutine to perform cleanup with provided cleanupInterval to remove unused limiters. If cleanupInterval is less or equal 0, the cleanup goroutine will not run and no cleanup will ever be available for this instance. Unused means when the limiter's available tokens are equal to the limit. There is no tracking for the last time used for a more memory-efficient solution. Adjust the cleanupInterval parameter to define how often the cleanup should be performed. Lowering the value means more cleanup frequency therefore more CPU usage but faster memory release. The cleanup time depends on cleanup execution time, meaning if the cleanup interval is set to 5s. It'll run cleanup on the 5th second and if cleanup execution takes 1s then the second cleanup will be performed at the 11th second.