package eviction import ( "s1d3sw1ped/steamcache2/vfs" "s1d3sw1ped/steamcache2/vfs/disk" "s1d3sw1ped/steamcache2/vfs/memory" ) // EvictionStrategy defines different eviction strategies type EvictionStrategy string const ( StrategyLRU EvictionStrategy = "lru" StrategyLFU EvictionStrategy = "lfu" StrategyFIFO EvictionStrategy = "fifo" StrategyLargest EvictionStrategy = "largest" StrategySmallest EvictionStrategy = "smallest" StrategyHybrid EvictionStrategy = "hybrid" ) // EvictLRU performs LRU eviction by removing least recently used files func EvictLRU(v vfs.VFS, bytesNeeded uint) uint { switch fs := v.(type) { case *memory.MemoryFS: return fs.EvictLRU(bytesNeeded) case *disk.DiskFS: return fs.EvictLRU(bytesNeeded) default: return 0 } } // EvictFIFO performs FIFO (First In First Out) eviction func EvictFIFO(v vfs.VFS, bytesNeeded uint) uint { switch fs := v.(type) { case *memory.MemoryFS: return fs.EvictFIFO(bytesNeeded) case *disk.DiskFS: return fs.EvictFIFO(bytesNeeded) default: return 0 } } // EvictBySizeAsc evicts smallest files first func EvictBySizeAsc(v vfs.VFS, bytesNeeded uint) uint { switch fs := v.(type) { case *memory.MemoryFS: return fs.EvictBySize(bytesNeeded, true) // true = ascending (smallest first) case *disk.DiskFS: return fs.EvictBySize(bytesNeeded, true) // true = ascending (smallest first) default: return 0 } } // EvictBySizeDesc evicts largest files first func EvictBySizeDesc(v vfs.VFS, bytesNeeded uint) uint { switch fs := v.(type) { case *memory.MemoryFS: return fs.EvictBySize(bytesNeeded, false) // false = descending (largest first) case *disk.DiskFS: return fs.EvictBySize(bytesNeeded, false) // false = descending (largest first) default: return 0 } } // EvictLargest evicts largest files first func EvictLargest(v vfs.VFS, bytesNeeded uint) uint { return EvictBySizeDesc(v, bytesNeeded) } // EvictSmallest evicts smallest files first func EvictSmallest(v vfs.VFS, bytesNeeded uint) uint { return EvictBySizeAsc(v, bytesNeeded) } // EvictLFU performs LFU (Least Frequently Used) eviction func EvictLFU(v vfs.VFS, bytesNeeded uint) uint { // For now, fall back to size-based eviction // TODO: Implement proper LFU tracking return EvictBySizeAsc(v, bytesNeeded) } // EvictHybrid implements a hybrid eviction strategy func EvictHybrid(v vfs.VFS, bytesNeeded uint) uint { // Use LRU as primary strategy, but consider size as tiebreaker return EvictLRU(v, bytesNeeded) } // GetEvictionFunction returns the eviction function for the given strategy func GetEvictionFunction(strategy EvictionStrategy) func(vfs.VFS, uint) uint { switch strategy { case StrategyLRU: return EvictLRU case StrategyLFU: return EvictLFU case StrategyFIFO: return EvictFIFO case StrategyLargest: return EvictLargest case StrategySmallest: return EvictSmallest case StrategyHybrid: return EvictHybrid default: return EvictLRU } }