Documentation
¶
Overview ¶
Package respcache is the v1.11 phase 6 in-memory LRU for hot list responses. Caches `(filter_query, cursor, user_scope) → serialized JSON body + ETag` for 60s; the v1.6 SSE event bus busts the cache on finding.created / finding.resolved / scan.completed events so operators never see stale data after a mutation.
Scope: the findings explorer (/api/v1/findings + /findings/rows) is the only consumer at v1.11.0 — it's the highest-traffic hot path on a busy daemon. /scans + /resources can layer onto the same cache shape in a v1.11.x follow-up if their numbers justify it.
Per-user keying: cache keys include the session user_id so an admin's full-scope filter view doesn't leak to a non-admin hitting the same query string. Token callers share an empty- scope bucket (their bearer-scope already lives in the cursor's filter set + the daemon enforces it server-side).
Index ¶
Constants ¶
const DefaultSize = 512
DefaultSize caps the cache at 512 distinct (filter, cursor, user) keys. Each entry is a JSON body + ETag string; at the median 50-row response size (~12 KB) the cache footprint stays under 8 MB. The LRU's promote-on-get behavior keeps hot pages resident.
const DefaultTTL = 60 * time.Second
DefaultTTL is the per-entry expiry. Tighter than the v1.6 ring's 5-min retention so a finding.created event can't race past a stale cache.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is the LRU + invalidation hook bundle.
func (*Cache) Get ¶
Get returns the cached entry + true when the key is present and not expired. Updates hit/miss counters atomically.
func (*Cache) HitRate ¶
HitRate returns the fraction of Get calls that found a live entry. Returns 0 when the cache hasn't been queried yet.
func (*Cache) Invalidate ¶
Invalidate drops every entry whose key starts with prefix. The LRU exposes Keys() so we scan + remove matches in one pass. O(n) over the cache size; acceptable at DefaultSize=512.
func (*Cache) Purge ¶
func (c *Cache) Purge()
Purge drops every entry — the catastrophic-reset path used when the daemon restarts under leader-election.
type Invalidator ¶
type Invalidator struct {
// contains filtered or unexported fields
}
Invalidator listens to the SSE bus + drops cache entries for mutating event types.
func NewInvalidator ¶
NewInvalidator wires the listener. Call Run to start consuming; stop by canceling the passed context.
func (*Invalidator) Run ¶
func (in *Invalidator) Run(ctx context.Context)
Run blocks until ctx is canceled. Subscribes to the v1.6 bus + busts the cache on each mutating event.
The prefix map below maps event type → cache key prefix; an event drops every cache entry whose key starts with the matching prefix. "findings:" covers /api/v1/findings + /findings/rows (both keyed via respcache.KeyFor("findings", ...)).