Help us shape the future of Go! Take the 2026 Go Developer Survey

dedup

package
v1.0.65 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package dedup implements a fixed-capacity LRU set used by the bus to suppress duplicate events that the DingTalk Stream SDK redelivers on reconnect (see plan invariant #2). The set stores only keys, never values, and is safe for concurrent use by multiple goroutines.

Index

Constants

View Source
const DefaultCapacity = 8192

DefaultCapacity is the default LRU size when LRU is constructed without an explicit capacity. 8192 is sized to absorb a typical reconnect-storm window (~5 min × 30 events/s) while staying memory-cheap (~256 KB at 32 bytes/key).

Variables

This section is empty.

Functions

This section is empty.

Types

type LRU

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

LRU is a fixed-capacity LRU set of string keys. Zero value is not usable; call New or NewWithCapacity.

func New

func New() *LRU

New returns an LRU with DefaultCapacity.

func NewWithCapacity

func NewWithCapacity(cap int) *LRU

NewWithCapacity returns an LRU sized to hold up to cap keys. cap must be > 0.

func (*LRU) Cap

func (l *LRU) Cap() int

Cap returns the configured capacity.

func (*LRU) Len

func (l *LRU) Len() int

Len returns the current number of stored keys.

func (*LRU) Seen

func (l *LRU) Seen(key string) bool

Seen reports whether key was already present and inserts it if not. The return value is true when the caller should treat the event as a duplicate (drop it) and false when this is the first occurrence.

Empty keys are never considered duplicates and are not stored — callers without a stable identifier should use RawEvent.DedupKey() which falls back to a content hash.

Jump to

Keyboard shortcuts

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