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

Method Resize

internal/lru/lru.go:275–291  ·  view source on GitHub ↗

Resize changes the cache size. Size of 0 means unlimited.

(size int)

Source from the content-addressed store, hash-verified

273
274// Resize changes the cache size. Size of 0 means unlimited.
275func (c *LRU[K, V]) Resize(size int) (evicted int) {
276 c.mu.Lock()
277 defer c.mu.Unlock()
278 if size <= 0 {
279 c.size = 0
280 return 0
281 }
282 diff := c.evictList.Length() - size
283 if diff < 0 {
284 diff = 0
285 }
286 for i := 0; i < diff; i++ {
287 c.removeOldest()
288 }
289 c.size = size
290 return diff
291}
292
293// Close destroys cleanup goroutine. To clean up the cache, run Purge() before Close().
294// func (c *LRU[K, V]) Close() {

Callers 1

TestLRUNoPurgeFunction · 0.80

Calls 2

removeOldestMethod · 0.95
LengthMethod · 0.65

Tested by 1

TestLRUNoPurgeFunction · 0.64