MCPcopy Create free account
hub / github.com/git-bug/git-bug / evictIfNeeded

Method evictIfNeeded

cache/subcache.go:618–642  ·  view source on GitHub ↗

evictIfNeeded will evict an entity from the cache if needed

()

Source from the content-addressed store, hash-verified

616
617// evictIfNeeded will evict an entity from the cache if needed
618func (sc *SubCache[EntityT, ExcerptT, CacheT]) evictIfNeeded() {
619 sc.mu.Lock()
620 defer sc.mu.Unlock()
621 if sc.lru.Len() <= sc.maxLoaded {
622 return
623 }
624
625 for _, id := range sc.lru.GetOldestToNewest() {
626 b := sc.cached[id]
627 if b.NeedCommit() {
628 continue
629 }
630
631 // as a form of assurance that evicted entities don't get manipulated, we lock them here.
632 // if something tries to do it anyway, it will lock the program and make it obvious.
633 b.Lock()
634
635 sc.lru.Remove(id)
636 delete(sc.cached, id)
637
638 if sc.lru.Len() <= sc.maxLoaded {
639 return
640 }
641 }
642}

Callers 3

SetCacheSizeMethod · 0.95
ResolveMethod · 0.95
addMethod · 0.95

Calls 5

GetOldestToNewestMethod · 0.80
LockMethod · 0.65
NeedCommitMethod · 0.65
RemoveMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected