package steamcache import ( "runtime/debug" "s1d3sw1ped/SteamCache2/vfs" "s1d3sw1ped/SteamCache2/vfs/cachestate" "time" "golang.org/x/exp/rand" ) func init() { // Set the GC percentage to 50%. This is a good balance between performance and memory usage. debug.SetGCPercent(50) } // RandomGC randomly deletes files until we've reclaimed enough space. func randomgc(vfss vfs.VFS, size uint) (uint, uint) { // Randomly delete files until we've reclaimed enough space. random := func(vfss vfs.VFS, stats []*vfs.FileInfo) int64 { randfile := stats[rand.Intn(len(stats))] sz := randfile.Size() err := vfss.Delete(randfile.Name()) if err != nil { return 0 } return sz } deletions := 0 targetreclaim := int64(size) var reclaimed int64 stats := vfss.StatAll() for { if reclaimed >= targetreclaim { break } reclaimed += random(vfss, stats) deletions++ } return uint(reclaimed), uint(deletions) } func cachehandler(fi *vfs.FileInfo, cs cachestate.CacheState) bool { return time.Since(fi.AccessTime()) < time.Second*10 // Put hot files in the fast vfs if equipped }