Documentation
¶
Overview ¶
Package cachebatch provides batch cache loading with bounded concurrency. It warms the HTTP cache for gallery, info box, and lightbox routes, skips already-cached entries, and blocks when discovery is active.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDiscoveryActive is returned when batch load is blocked because discovery is running. ErrDiscoveryActive = errors.New("cache batch load blocked: discovery is active") // ErrAlreadyRunning is returned when a batch load run is already in progress. ErrAlreadyRunning = errors.New("cache batch load already running") )
Functions ¶
This section is empty.
Types ¶
type BatchLoadQueries ¶
type BatchLoadQueries interface {
GetBatchLoadTargets(ctx context.Context) ([]gallerydb.BatchLoadTarget, error)
HttpCacheExistsByKey(ctx context.Context, key string) (bool, error)
}
BatchLoadQueries is the minimal interface needed for batch load.
type Config ¶
type Config struct {
// GetQueries returns HandlerQueries-like access; must provide GetBatchLoadTargets
// and HttpCacheExistsByKey. Typically from dbRoPool.Get().Queries (CustomQueries).
GetQueries func() (BatchLoadQueries, func())
// GetHandler returns the HTTP handler wrapped with full middleware chain
// (cache middleware, compression middleware, etc.)
GetHandler func() http.Handler
// GetETagVersion returns the current ETag version for cache keys.
GetETagVersion func() string
// ModuleStateService for discovery active check; nil skips guard.
ModuleStateService moduleStateService
}
Config holds dependencies for BatchLoadManager.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager runs batch cache load with bounded concurrency.
func (*Manager) GetBatchLoadSnapshot ¶ added in v0.8.0
GetBatchLoadSnapshot returns a snapshot of the current metrics for the metrics collector.
type Metrics ¶
type Metrics struct {
TargetsTotal int64 // total targets from GetBatchLoadTargets
TargetsScheduled int64 // enqueued for processing
TargetsCompleted int64 // completed successfully
TargetsFailed int64 // request failed
TargetsSkipped int64 // already cached (HttpCacheExistsByKey)
ThrottlesSkipped int64 // number of times scheduling was delayed (queue >80% full)
BackpressureSkipped int64 // targets skipped due to backpressure (queue >95% full)
InFlight int64 // currently in progress
IsRunning int32 // 1 if a run is active, 0 otherwise
LastStartedAt int64 // Unix time of last Run start
LastFinishedAt int64 // Unix time of last Run finish
}
Metrics holds batch load run statistics. All int64 fields are updated with sync/atomic; use Snapshot for a consistent view.
func (*Metrics) RecordBackpressureSkipped ¶
func (m *Metrics) RecordBackpressureSkipped()
RecordBackpressureSkipped increments backpressure skipped.
func (*Metrics) RecordCompleted ¶
func (m *Metrics) RecordCompleted()
RecordCompleted increments completed and decrements in-flight.
func (*Metrics) RecordFailed ¶
func (m *Metrics) RecordFailed()
RecordFailed increments failed and decrements in-flight.
func (*Metrics) RecordThrottled ¶
func (m *Metrics) RecordThrottled()
RecordThrottled increments the throttle counter (scheduling was delayed due to high queue utilization).