Source File
defaultcache.go
Belonging Package
github.com/freeeve/gochickpeas/gql
// The implicit per-snapshot plan cache behind Run/RunWithParams: library// callers get template caching (skip parse + plan on repeats) with no// setup, per the census verdict -- every measured flip is timing-neutral// and the flip-aware bypass routes structurally flipped templates through// sighted planning, so the cached path does no harm. The registry keys// caches by WEAK snapshot pointers with a GC cleanup, so dropping a// snapshot drops its cache; a cache never outlives (or pins) its// snapshot. Callers wanting the literal-planned path explicitly --// benchmarks separating cold from warm, plan-shape experiments that// mutate planner thresholds between runs -- use RunUncached.package gqlimport (chickpeas)var (defaultCachesMu sync.MutexdefaultCaches = map[weak.Pointer[chickpeas.Snapshot]]*PlanCache{})// DefaultCacheFor returns the snapshot's implicit plan cache, creating it// on first use (DefaultCacheBytes budget). Run and RunWithParams route// through it; sharing the same cache with explicit PlanCache calls is// fine but unnecessary.func ( *chickpeas.Snapshot) *PlanCache {:= weak.Make()defaultCachesMu.Lock()defer defaultCachesMu.Unlock()if , := defaultCaches[]; {return}:= NewPlanCache(0)defaultCaches[] =runtime.AddCleanup(, func( weak.Pointer[chickpeas.Snapshot]) {defaultCachesMu.Lock()delete(defaultCaches, )defaultCachesMu.Unlock()}, )return}
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |