package steamcache import ( "runtime/debug" "s1d3sw1ped/SteamCache2/vfs" "s1d3sw1ped/SteamCache2/vfs/cachestate" "sort" "time" ) func init() { // Set the GC percentage to 50%. This is a good balance between performance and memory usage. debug.SetGCPercent(50) } // lruGC deletes files in LRU order until enough space is reclaimed. func lruGC(vfss vfs.VFS, size uint) (uint, uint) { deletions := 0 var reclaimed uint stats := vfss.StatAll() sort.Slice(stats, func(i, j int) bool { return stats[i].AccessTime().Before(stats[j].AccessTime()) }) for _, s := range stats { sz := uint(s.Size()) err := vfss.Delete(s.Name()) if err != nil { continue } reclaimed += sz deletions++ if reclaimed >= size { break } } return 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 }