Documentation
¶
Overview ¶
Package countcache keeps the audience counts that read every contact of a workspace for a short while (review 2026-11 OP-12): the Audience header's counts (about 300 ms on a million contacts) and a segment's count (about a second for two conditions).
Only counts that took MinCost or longer are kept: a quick count is cheaper to run again than to serve stale, so small workspaces always see fresh numbers. An entry lives for TTL. A change this process makes to a workspace's contacts, lists or suppressions drops the workspace's entries at once (Changed, wired to the audit log, which every such change writes); a change another process makes shows within TTL. Concurrent misses for the same entry run one count and share its result.
Index ¶
Constants ¶
const DefaultMax = 4096
DefaultMax bounds the entries kept, across workspaces.
const DefaultTTL = time.Minute
DefaultTTL is how long a count is served without being counted again.
const SlowCount = 250 * time.Millisecond
SlowCount is the MinCost the app uses: a quarter of a second, about what the Audience header's counts take on a million contacts.
Variables ¶
This section is empty.
Functions ¶
func AudienceChange ¶
AudienceChange reports whether an audit action changes what the counts count ("contacts.erase", "list.delete", "import.finish"…).
func Get ¶
func Get[T any](ctx context.Context, c *Cache, ws uuid.UUID, name string, load func(context.Context) (T, error)) (val T, at time.Time, err error)
Get returns the workspace's count called name, counting it with load when it isn't kept or is older than the TTL. at is when the value was counted. A nil cache always loads.
Types ¶
type Cache ¶
type Cache struct {
// MinCost is the least time a count must have taken to be kept; zero
// keeps every count. Set it before the cache is used.
MinCost time.Duration
// contains filtered or unexported fields
}
Cache is safe for concurrent use. The zero value isn't: use New.
func New ¶
New returns a cache; ttl ≤ 0 means DefaultTTL, max ≤ 0 DefaultMax, and a nil now the wall clock.