MCPcopy Create free account
hub / github.com/PostHog/duckgres / Put

Method Put

cmd/cache-proxy/cache.go:193–222  ·  view source on GitHub ↗

Put stores data in the cache, evicting old entries if needed.

(key string, data []byte)

Source from the content-addressed store, hash-verified

191
192 // Durable recency is optional for tests and always enabled by main. Exact
193 // LRU updates remain synchronous; only coarse mtime persistence is queued.
194 recency *recencyWriter
195 recencyNow func() time.Time
196 recencyInterval time.Duration
197 // commitMu linearizes the short final rename/accounting/recency commit with
198 // shutdown without coupling lifecycle progress to a potentially blocking
199 // pressure-driven unlink under mu.
200 commitMu sync.Mutex
201
202 convergenceCancel context.CancelFunc
203 convergenceDone chan struct{}
204 convergenceWake chan struct{}
205 closing atomic.Bool
206}
207
208const defaultCacheMaxEntries = 1_000_000
209
210const (
211 defaultCacheBlockSizeBytes int64 = 8 << 20
212 capacityRecoveryRequiredSamples = 2
213 defaultConvergenceInterval = time.Millisecond
214 estimatedExactIndexBytesPerEntry = 256
215)
216
217type diskSpace struct {
218 TotalBytes int64
219 FreeBytes int64
220}
221
222type capacityProvider func(string) (diskSpace, error)
223
224type cacheDirectory interface {
225 ReadDir(int) ([]os.DirEntry, error)

Callers 5

TestHandlePeerHasAndGetFunction · 0.80
TestDiskCachePutGetHasFunction · 0.80
TestDiskCacheOpenFunction · 0.80
TestDiskCacheEvictionFunction · 0.80

Calls 3

evictOldestMethod · 0.95
IsValidCacheKeyFunction · 0.85
NowMethod · 0.80

Tested by 5

TestHandlePeerHasAndGetFunction · 0.64
TestDiskCachePutGetHasFunction · 0.64
TestDiskCacheOpenFunction · 0.64
TestDiskCacheEvictionFunction · 0.64