purge immediately removes an entry from the cache, even if it has open references. Safety: Must only be called while the Cache lock is held
(fileID uuid.UUID)
| 259 | // references. |
| 260 | // Safety: Must only be called while the Cache lock is held |
| 261 | func (c *Cache) purge(fileID uuid.UUID) { |
| 262 | entry, ok := c.data[fileID] |
| 263 | if !ok { |
| 264 | // If we land here, it's probably because of a fetch attempt that |
| 265 | // resulted in an error, and got purged already. It may also be an |
| 266 | // erroneous extra close, but we can't really distinguish between those |
| 267 | // two cases currently. |
| 268 | return |
| 269 | } |
| 270 | |
| 271 | // Purge the file from the cache. |
| 272 | c.currentOpenFiles.Dec() |
| 273 | ev, err := entry.value.Load() |
| 274 | if err == nil { |
| 275 | c.currentCacheSize.Add(-1 * float64(ev.Size)) |
| 276 | } |
| 277 | |
| 278 | delete(c.data, fileID) |
| 279 | } |
| 280 | |
| 281 | // Count returns the number of files currently in the cache. |
| 282 | // Mainly used for unit testing assertions. |