Put stores data in the cache, evicting old entries if needed.
(key string, data []byte)
| 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 | |
| 208 | const defaultCacheMaxEntries = 1_000_000 |
| 209 | |
| 210 | const ( |
| 211 | defaultCacheBlockSizeBytes int64 = 8 << 20 |
| 212 | capacityRecoveryRequiredSamples = 2 |
| 213 | defaultConvergenceInterval = time.Millisecond |
| 214 | estimatedExactIndexBytesPerEntry = 256 |
| 215 | ) |
| 216 | |
| 217 | type diskSpace struct { |
| 218 | TotalBytes int64 |
| 219 | FreeBytes int64 |
| 220 | } |
| 221 | |
| 222 | type capacityProvider func(string) (diskSpace, error) |
| 223 | |
| 224 | type cacheDirectory interface { |
| 225 | ReadDir(int) ([]os.DirEntry, error) |