counters

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SharedCounter = NewCounter[uint32]().WithGC()

Functions

This section is empty.

Types

type Counter

type Counter[T SupportedUIntType] struct {
	// contains filtered or unexported fields
}

func NewCounter

func NewCounter[T SupportedUIntType]() *Counter[T]

NewCounter create new counter

func (*Counter[T]) CountMaps added in v1.2.10

func (this *Counter[T]) CountMaps() int

func (*Counter[T]) GC

func (this *Counter[T]) GC()

GC garbage expired items

func (*Counter[T]) Get

func (this *Counter[T]) Get(key uint64) T

Get value of key

func (*Counter[T]) GetKey

func (this *Counter[T]) GetKey(key string) T

GetKey get value of string key

func (*Counter[T]) Increase

func (this *Counter[T]) Increase(key uint64, lifeSeconds int) T

Increase key

func (*Counter[T]) IncreaseKey

func (this *Counter[T]) IncreaseKey(key string, lifeSeconds int) T

IncreaseKey increase string key

func (*Counter[T]) Reset

func (this *Counter[T]) Reset(key uint64)

Reset key

func (*Counter[T]) ResetKey

func (this *Counter[T]) ResetKey(key string)

ResetKey string key

func (*Counter[T]) TotalItems

func (this *Counter[T]) TotalItems() int

TotalItems get items count

func (*Counter[T]) WithGC

func (this *Counter[T]) WithGC() *Counter[T]

WithGC start the counter with gc automatically

type Item

type Item[T SupportedUIntType] struct {
	// contains filtered or unexported fields
}

func NewItem

func NewItem[T SupportedUIntType](lifeSeconds int) Item[T]

func (*Item[T]) Increase

func (this *Item[T]) Increase() (result T)

func (*Item[T]) IsExpired

func (this *Item[T]) IsExpired(currentTime int64) bool

func (*Item[T]) IsOk added in v1.3.3

func (this *Item[T]) IsOk() bool

func (*Item[T]) Reset

func (this *Item[T]) Reset()

func (*Item[T]) Sum

func (this *Item[T]) Sum() (result T)

type SupportedUIntType added in v1.3.0

type SupportedUIntType interface {
	uint32 | uint64
}

Jump to

Keyboard shortcuts

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