RemoveAsync removes an entry from cache asynchronously using worker pool
(key string)
| 337 | |
| 338 | // RemoveAsync removes an entry from cache asynchronously using worker pool |
| 339 | func (fc *FileCache) RemoveAsync(key string) { |
| 340 | // First check if cache is closed |
| 341 | fc.closeMutex.RLock() |
| 342 | if fc.closed { |
| 343 | fc.closeMutex.RUnlock() |
| 344 | return |
| 345 | } |
| 346 | fc.closeMutex.RUnlock() |
| 347 | |
| 348 | // Try to acquire a worker from the pool |
| 349 | select { |
| 350 | case <-fc.workerPool: |
| 351 | // Got a worker, proceed with async removal |
| 352 | go func() { |
| 353 | defer func() { |
| 354 | // Return worker to pool |
| 355 | fc.workerPool <- struct{}{} |
| 356 | }() |
| 357 | fc.Remove(key) |
| 358 | }() |
| 359 | default: |
| 360 | // Worker pool exhausted, remove synchronously to prevent memory leak |
| 361 | log.Debugf("Worker pool exhausted, removing cache entry synchronously: %s", key) |
| 362 | fc.Remove(key) |
| 363 | } |
| 364 | } |
no test coverage detected