diff --git a/CHANGELOG.md b/CHANGELOG.md index 6366a4d92..499b5b925 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ **Master** +- Sort cache entries only when choosing eviction order. [Oskar Eichler](https://github.com/OskarEichler) + Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprockets/blob/master/UPGRADING.md # 4.4.1 diff --git a/README.md b/README.md index 958b44cd4..4906bcee8 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,8 @@ If you want to work on Sprockets or better understand how it works read [How Spr ## Behavior Overview +Initial file cache size calculation does not sort entries; eviction still sorts by modification time before choosing files to remove. + You can interact with Sprockets primarily through directives and file extensions. This section covers how to use each of these things, and the defaults that ship with Sprockets. Since you are likely using Sprockets through another framework (such as the [Rails asset pipeline](http://guides.rubyonrails.org/asset_pipeline.html)), there will be configuration options you can toggle that will change behavior such as what directories or files get compiled. For that documentation you should see your framework's documentation. diff --git a/lib/sprockets/cache/file_store.rb b/lib/sprockets/cache/file_store.rb index 85d7f7972..43ff4977f 100644 --- a/lib/sprockets/cache/file_store.rb +++ b/lib/sprockets/cache/file_store.rb @@ -149,8 +149,7 @@ def clear(options=nil) private # Internal: Get all cache files along with stats. # - # Returns an Array of [String filename, File::Stat] pairs sorted by - # mtime. + # Returns an Array of [String filename, File::Stat] pairs. def find_caches Dir.glob(File.join(@root, '**/*.cache')).reduce([]) { |stats, filename| stat = safe_stat(filename) @@ -158,7 +157,7 @@ def find_caches # dir.glob and the next stat stats << [filename, stat] if stat stats - }.sort_by { |_, stat| stat.mtime.to_i } + } end def size @@ -185,7 +184,7 @@ def safe_open(path, &block) def gc! start_time = Time.now - caches = find_caches + caches = find_caches.sort_by { |_, stat| stat.mtime.to_i } size = compute_size(caches) delete_caches, keep_caches = caches.partition { |filename, stat|