@@ -389,119 +389,6 @@ func printCacheInfo(info CacheInfo) {
389
389
}
390
390
}
391
391
392
- // cleanCache removes expired entries from the cache
393
- func cleanCache (cacheDir string , maxAgeInDays , maxSizeMB int ) error {
394
- // Check if cache directory exists
395
- _ , err := os .Stat (cacheDir )
396
- if os .IsNotExist (err ) {
397
- // Nothing to clean
398
- return nil
399
- }
400
- if err != nil {
401
- return err
402
- }
403
-
404
- // Get current cache information
405
- info , err := getCacheInfo (cacheDir )
406
- if err != nil {
407
- return err
408
- }
409
-
410
- // If cache is already below limits, do nothing
411
- maxSizeBytes := int64 (maxSizeMB ) * 1024 * 1024
412
- if info .Size <= maxSizeBytes && time .Since (info .OldestEntry ).Hours ()/ 24 <= float64 (maxAgeInDays ) {
413
- return nil
414
- }
415
-
416
- // Find entries to clean
417
- entries , err := filepath .Glob (filepath .Join (cacheDir , "*" ))
418
- if err != nil {
419
- return err
420
- }
421
-
422
- // Sort entries by age, oldest first
423
- type Entry struct {
424
- Path string
425
- ModTime time.Time
426
- }
427
-
428
- var sortedEntries []Entry
429
- for _ , path := range entries {
430
- info , err := os .Stat (path )
431
- if err != nil {
432
- continue
433
- }
434
- if info .IsDir () {
435
- sortedEntries = append (sortedEntries , Entry {
436
- Path : path ,
437
- ModTime : info .ModTime (),
438
- })
439
- }
440
- }
441
-
442
- // Remove entries that exceed age limit
443
- cutoffTime := time .Now ().AddDate (0 , 0 , - maxAgeInDays )
444
- for _ , entry := range sortedEntries {
445
- if entry .ModTime .Before (cutoffTime ) {
446
- err := os .RemoveAll (entry .Path )
447
- if err != nil {
448
- fmt .Fprintf (os .Stderr , "Warning: Failed to remove %s: %v\n " , entry .Path , err )
449
- }
450
- }
451
- }
452
-
453
- // Recheck cache size after age-based cleanup
454
- info , err = getCacheInfo (cacheDir )
455
- if err != nil {
456
- return err
457
- }
458
-
459
- // If still over size limit, remove oldest entries until under limit
460
- if info .Size > maxSizeBytes {
461
- // Re-scan entries after previous cleanup
462
- entries , err = filepath .Glob (filepath .Join (cacheDir , "*" ))
463
- if err != nil {
464
- return err
465
- }
466
-
467
- // Rebuild sorted entries
468
- sortedEntries = []Entry {}
469
- for _ , path := range entries {
470
- info , err := os .Stat (path )
471
- if err != nil {
472
- continue
473
- }
474
- if info .IsDir () {
475
- sortedEntries = append (sortedEntries , Entry {
476
- Path : path ,
477
- ModTime : info .ModTime (),
478
- })
479
- }
480
- }
481
-
482
- // Remove oldest entries until under size limit
483
- for _ , entry := range sortedEntries {
484
- err := os .RemoveAll (entry .Path )
485
- if err != nil {
486
- fmt .Fprintf (os .Stderr , "Warning: Failed to remove %s: %v\n " , entry .Path , err )
487
- continue
488
- }
489
-
490
- // Recheck cache size after removal
491
- info , err = getCacheInfo (cacheDir )
492
- if err != nil {
493
- return err
494
- }
495
-
496
- if info .Size <= maxSizeBytes {
497
- break
498
- }
499
- }
500
- }
501
-
502
- return nil
503
- }
504
-
505
392
// flushCache completely empties the cache but preserves the index.json file
506
393
func flushCache (cacheDir string ) error {
507
394
// Check if cache directory exists
0 commit comments