counter

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

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

Counter is a sliding window counter implemented with a TTL cache

func New

func New(ttl time.Duration, opts ...Option) *Counter

NewCounter creates a new Counter

func (*Counter) DeleteExpired

func (c *Counter) DeleteExpired()

DeleteExpired deletes expired items from the cache

func (*Counter) Get

func (c *Counter) Get(key string, window time.Time) (int, error)

Get returns the count for the given key and window

func (*Counter) Increment

func (c *Counter) Increment(key string, currWindow time.Time) error

Increment increments the count for the given key and window

type Option

type Option func(*Counter)

func DisableAutoDeleteExpired

func DisableAutoDeleteExpired() Option

DisableAutoDeleteExpired disables the automatic deletion of expired items

func WithCapacity

func WithCapacity(capacity uint64) Option

WithCapacity sets the maximum number of items to store in the cache

Jump to

Keyboard shortcuts

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