Sha256: 7b2134bad87e4638c436c44e5990974537b20e37c1efb6209f5e0dc4e28aadd0

Contents?: true

Size: 822 Bytes

Versions: 4

Compression:

Stored size: 822 Bytes

Contents

class DiskStore
  class Reaper
    module LRU
      def files_to_evict
        # Collect and sort files based on last access time
        sorted_files = files
          .map { |file|
            st = File.stat(file)
            { path: file, last_fetch: st.atime, size: st.size }
          }
          .sort { |a, b| a[:last_fetch] <=> b[:last_fetch] } # Oldest first

        # Determine which files to evict
        space_to_evict = current_cache_size - maximum_cache_size
        space_evicted = 0
        evictions = []
        while space_evicted < space_to_evict
          evicted_file = sorted_files.shift
          space_evicted += evicted_file[:size]
          evictions << evicted_file
        end

        evictions
      end

      def directories_to_evict
        empty_directories
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
disk_store-0.4.1 lib/disk_store/eviction_strategies/lru.rb
disk_store-0.4.0 lib/disk_store/eviction_strategies/lru.rb
disk_store-0.3.0 lib/disk_store/eviction_strategies/lru.rb
disk_store-0.2.2 lib/disk_store/eviction_strategies/lru.rb