|
|
@ -24,6 +24,7 @@ import ( |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"path" |
|
|
|
"path" |
|
|
|
"runtime/debug" |
|
|
|
"runtime/debug" |
|
|
|
|
|
|
|
"sort" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"sync" |
|
|
|
"sync" |
|
|
|
"time" |
|
|
|
"time" |
|
|
@ -344,6 +345,29 @@ func (b *bucketMetacache) cleanup() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If above limit, remove the caches with the oldest handout time.
|
|
|
|
|
|
|
|
if len(caches)-len(remove) > metacacheMaxEntries { |
|
|
|
|
|
|
|
remainCaches := make([]metacache, 0, len(caches)-len(remove)) |
|
|
|
|
|
|
|
for id, cache := range caches { |
|
|
|
|
|
|
|
if _, ok := remove[id]; ok { |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
remainCaches = append(remainCaches, cache) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if len(remainCaches) > metacacheMaxEntries { |
|
|
|
|
|
|
|
// Sort oldest last...
|
|
|
|
|
|
|
|
sort.Slice(remainCaches, func(i, j int) bool { |
|
|
|
|
|
|
|
return remainCaches[i].lastHandout.Before(remainCaches[j].lastHandout) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
// Keep first metacacheMaxEntries...
|
|
|
|
|
|
|
|
for _, cache := range remainCaches[metacacheMaxEntries:] { |
|
|
|
|
|
|
|
if time.Since(cache.lastHandout) > time.Hour { |
|
|
|
|
|
|
|
remove[cache.id] = struct{}{} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for id := range remove { |
|
|
|
for id := range remove { |
|
|
|
b.deleteCache(id) |
|
|
|
b.deleteCache(id) |
|
|
|
} |
|
|
|
} |
|
|
|