Skip to content

Commit 7c2ab3f

Browse files
authored
Sychronize cache sweeper action to prevent race condition (#189)
1 parent 463a502 commit 7c2ab3f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/propshaft/load_path.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,13 @@ def cache_sweeper
4444
@cache_sweeper ||= begin
4545
exts_to_watch = Mime::EXTENSION_LOOKUP.map(&:first)
4646
files_to_watch = Array(paths).collect { |dir| [ dir.to_s, exts_to_watch ] }.to_h
47+
mutex = Mutex.new
4748

4849
Rails.application.config.file_watcher.new([], files_to_watch) do
49-
clear_cache
50+
mutex.synchronize do
51+
clear_cache
52+
seed_cache
53+
end
5054
end
5155
end
5256
end
@@ -81,6 +85,10 @@ def clear_cache
8185
@cached_asset_paths_by_glob = nil
8286
end
8387

88+
def seed_cache
89+
assets_by_path
90+
end
91+
8492
def dedup(paths)
8593
paths = Array(paths).map { |path| Pathname.new(path) }
8694
deduped = [].tap do |deduped|

0 commit comments

Comments
 (0)