MCPcopy Index your code
hub / github.com/coder/coder / newCache

Function newCache

coderd/cryptokeys/cache.go:126–150  ·  view source on GitHub ↗
(ctx context.Context, logger slog.Logger, fetcher Fetcher, feature codersdk.CryptoKeyFeature, opts ...func(*cache))

Source from the content-addressed store, hash-verified

124}
125
126func newCache(ctx context.Context, logger slog.Logger, fetcher Fetcher, feature codersdk.CryptoKeyFeature, opts ...func(*cache)) *cache {
127 cache := &cache{
128 clock: quartz.NewReal(),
129 logger: logger.With(slog.F("feature", feature)),
130 fetcher: fetcher,
131 feature: feature,
132 }
133
134 for _, opt := range opts {
135 opt(cache)
136 }
137 cache.logger.Debug(ctx, "created new key cache")
138
139 cache.cond = sync.NewCond(&cache.mu)
140 //nolint:gocritic // We need to be able to read the keys in order to cache them.
141 cache.ctx, cache.cancel = context.WithCancel(dbauthz.AsKeyReader(ctx))
142 cache.refresher = cache.clock.AfterFunc(refreshInterval, cache.refresh)
143
144 keys, err := cache.cryptoKeys(cache.ctx)
145 if err != nil {
146 cache.logger.Critical(cache.ctx, "failed initial fetch", slog.Error(err))
147 }
148 cache.keys = keys
149 return cache
150}
151
152func (c *cache) EncryptingKey(ctx context.Context) (string, interface{}, error) {
153 if !isEncryptionKeyFeature(c.feature) {

Callers 2

NewSigningCacheFunction · 0.85
NewEncryptionCacheFunction · 0.85

Calls 3

cryptoKeysMethod · 0.95
AsKeyReaderFunction · 0.92
ErrorMethod · 0.45

Tested by

no test coverage detected