Documentation
¶
Overview ¶
Package acceptcache stores the result of a CanAccept() call so the scheduler can reuse it on the next considerWork cycle without paying the (potentially expensive) cost of re-evaluating CanAccept. The entries expire after a configurable TTL to avoid acting on stale decisions.
The slice, timestamp, and mutex are unexported, so callers can only interact through Add / Consume / TakeMatching, which always acquire the lock correctly. Prefer TakeMatching in considerWork so unrelated cached IDs are not discarded and an empty intersection is treated as a miss.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a TTL-bounded bucket of accepted task IDs. Multiple producers (the background poller, the scheduler writing leftover remainders) may call Add concurrently with the scheduler calling Consume.
Add de-duplicates: the same task ID added more than once between Consume calls is stored once. Without this, a backlog that stays unowned across many poll cycles would re-Add the full set every cycle and grow the slice unboundedly (the TTL never expires while Add keeps refreshing it).
func (*Cache) Add ¶
Add appends not-yet-cached ids to the cache and refreshes the TTL baseline. Duplicate ids (already present since the last Consume) are skipped. Callers may add from any goroutine.
func (*Cache) Consume ¶
Consume returns all cached ids and clears the cache. If the TTL has elapsed since the last Add, the cache is discarded and nil is returned (the caller should fall back to calling CanAccept).
func (*Cache) TakeMatching ¶
TakeMatching removes and returns cached ids that appear in candidates. Unmatched cached ids are left in place for later considerWork calls.
hadFresh is false when the cache is empty or TTL-expired (caller should call CanAccept for the full candidate set). hadFresh is true when the cache held live entries — even if matched is empty. An empty match with hadFresh true is a cache miss for this candidate set, not a CanAccept refusal; the caller must call CanAccept rather than treating it as deny.