memory

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

Types

type Option

type Option func(o *Options)

func WithErrorHandler

func WithErrorHandler(errorHandler func(err error)) Option

type Options

type Options struct {
	ErrorHandler func(err error)
}

func NewOptions

func NewOptions(opts ...Option) *Options

Jump to

Keyboard shortcuts

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