DedupCache

class
yoltra/dedup.py:40

A TTL-windowed fingerprint cache for opt-in event deduplication.

Constructor

constructor

Initialize self. See help(type(self)) for accurate signature.

signature
new(window_ms?, max_size?, key_window_ms?, clock?): None

Initialize self. See help(type(self)) for accurate signature.

Parameters

NameTypeDescription
window_ms?float
NameTypeDescription
max_size?int
NameTypeDescription
key_window_ms?float
NameTypeDescription
clock?() => float

Returns

None

Properties

NameTypeDescription
sizeintNumber of fingerprints currently cached.

Methods

clear

Drop all cached fingerprints (the suppression count is preserved).

signature
clear(): None

Drop all cached fingerprints (the suppression count is preserved).

Returns

None

fingerprint

Compute a content fingerprint for an event. Uses `json.dumps(payload, sort_keys=True, default=str)` so structurally equal payloads (regardless of dict key order) share a fingerprint. Non-serializable payloads (e.g. containing cycles) fall back to an `id()` + timestamp fingerprint, so they are effectively **never** deduplicated rather than falsely coalesced.

signature
fingerprint(channel, type, payload): str

Compute a content fingerprint for an event. Uses `json.dumps(payload, sort_keys=True, default=str)` so structurally equal payloads (regardless of dict key order) share a fingerprint. Non-serializable payloads (e.g. containing cycles) fall back to an `id()` + timestamp fingerprint, so they are effectively **never** deduplicated rather than falsely coalesced.

Parameters

NameTypeDescription
channelstrEvent channel.
NameTypeDescription
typestrEvent type.
NameTypeDescription
payloadanyEvent payload.

Returns

strA stable string fingerprint.

is_duplicate

Whether this emit should be skipped as a duplicate. Records the event's fingerprint as a side effect (so a later identical event within the window is caught). When neither content dedup nor a `dedup_key` is active, returns `False` immediately without touching the cache.

signature
is_duplicate(channel, type, payload, dedup_key?): bool

Whether this emit should be skipped as a duplicate. Records the event's fingerprint as a side effect (so a later identical event within the window is caught). When neither content dedup nor a `dedup_key` is active, returns `False` immediately without touching the cache.

Parameters

NameTypeDescription
channelstrEvent channel.
NameTypeDescription
typestrEvent type.
NameTypeDescription
payloadanyEvent payload (content-fingerprinted when no key is given).
NameTypeDescription
dedup_key?str | NoneOptional identity key for per-emit dedup.

Returns

bool`True` if a matching fingerprint was seen within the window.