acceptcache

package
v1.29.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0, MIT Imports: 2 Imported by: 0

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.

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 stores accepted task IDs and the candidates checked by CanAccept. All methods are safe to call concurrently.

func New

func New(ttl time.Duration) *Cache

New constructs a Cache whose entries expire after ttl.

func (*Cache) Add

func (c *Cache) Add(ids []int64)

Add appends accepted IDs, marks them checked, and refreshes the TTL baseline. Duplicate IDs are skipped.

func (*Cache) Consume

func (c *Cache) Consume() []int64

Consume returns all cached accepted IDs, retaining their checked coverage. Expired evaluations are discarded and return nil.

func (*Cache) Forget added in v1.29.0

func (c *Cache) Forget(ids []int64)

Forget removes acceptance and checked coverage without refreshing the TTL.

func (*Cache) GetMatching added in v1.29.0

func (c *Cache) GetMatching(candidates []int64) (matched []int64, checked bool)

GetMatching returns accepted candidates without consuming them. checked is true only when every candidate has a fresh evaluation; matched can still contain accepted IDs when some candidates have not been checked.

func (*Cache) Refresh added in v1.29.0

func (c *Cache) Refresh()

Refresh allows refused or consumed IDs to be checked again while retaining accepted IDs. It does not refresh the TTL.

func (*Cache) Store added in v1.29.0

func (c *Cache) Store(candidates, accepted []int64)

Store replaces the cached evaluation, including an empty accepted result.

func (*Cache) TakeMatching

func (c *Cache) TakeMatching(candidates []int64) (matched []int64, hadFresh bool)

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.

Jump to

Keyboard shortcuts

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