MCPcopy
hub / github.com/go-gorm/gorm / deleteExpired

Method deleteExpired

internal/lru/lru.go:324–339  ·  view source on GitHub ↗

deleteExpired deletes expired records from the oldest bucket, waiting for the newest entry in it to expire first.

()

Source from the content-addressed store, hash-verified

322// deleteExpired deletes expired records from the oldest bucket, waiting for the newest entry
323// in it to expire first.
324func (c *LRU[K, V]) deleteExpired() {
325 c.mu.Lock()
326 bucketIdx := c.nextCleanupBucket
327 timeToExpire := time.Until(c.buckets[bucketIdx].newestEntry)
328 // wait for newest entry to expire before cleanup without holding lock
329 if timeToExpire > 0 {
330 c.mu.Unlock()
331 time.Sleep(timeToExpire)
332 c.mu.Lock()
333 }
334 for _, ent := range c.buckets[bucketIdx].entries {
335 c.removeElement(ent)
336 }
337 c.nextCleanupBucket = (c.nextCleanupBucket + 1) % numBuckets
338 c.mu.Unlock()
339}
340
341// addToBucket adds entry to expire bucket so that it will be cleaned up when the time comes. Has to be called with lock!
342func (c *LRU[K, V]) addToBucket(e *Entry[K, V]) {

Callers 1

NewLRUFunction · 0.80

Calls 1

removeElementMethod · 0.95

Tested by

no test coverage detected