must hold sto.mu. Reports whether an item was removed.
()
| 108 | // must hold sto.mu. |
| 109 | // Reports whether an item was removed. |
| 110 | func (sto *Storage) removeOldest() bool { |
| 111 | ctx := context.TODO() |
| 112 | k, v := sto.lru.RemoveOldest() |
| 113 | if v == nil { |
| 114 | return false |
| 115 | } |
| 116 | sb := v.(blob.SizedRef) |
| 117 | // TODO: run these without sto.mu held in background |
| 118 | // goroutine? at least pass a context? |
| 119 | err := sto.cache.RemoveBlobs(ctx, []blob.Ref{sb.Ref}) |
| 120 | if err != nil { |
| 121 | log.Printf("proxycache: could not remove oldest blob %v (%d bytes): %v", sb.Ref, sb.Size, err) |
| 122 | sto.lru.Add(k, v) |
| 123 | return false |
| 124 | } |
| 125 | if sto.debug { |
| 126 | log.Printf("proxycache: removed blob %v (%d bytes)", sb.Ref, sb.Size) |
| 127 | } |
| 128 | sto.cacheBytes -= int64(sb.Size) |
| 129 | return true |
| 130 | } |
| 131 | |
| 132 | func (sto *Storage) touch(sb blob.SizedRef) { |
| 133 | key := sb.Ref.String() |
no test coverage detected