File tree Expand file tree Collapse file tree 6 files changed +61
-7
lines changed Expand file tree Collapse file tree 6 files changed +61
-7
lines changed Original file line number Diff line number Diff line change
1
+ * Only clear ActionView cache in development on file changes
2
+
3
+ To speed up development mode, view caches are only cleared when files in
4
+ the view paths have changed. Applications which have implemented custom
5
+ ActionView::Resolver subclasses may need to add their own cache clearing.
6
+
7
+ * John Hawthorn*
8
+
1
9
## Rails 6.0.0.beta3 (March 11, 2019) ##
2
10
3
11
* Only accept formats from registered mime types
Original file line number Diff line number Diff line change @@ -81,6 +81,7 @@ module ActionView
81
81
end
82
82
end
83
83
84
+ autoload :CacheExpiry
84
85
autoload :TestCase
85
86
86
87
def self . eager_load!
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ class CacheExpiry
5
+ class Executor
6
+ def initialize ( watcher :)
7
+ @cache_expiry = CacheExpiry . new ( watcher : watcher )
8
+ end
9
+
10
+ def before ( target )
11
+ @cache_expiry . clear_cache_if_necessary
12
+ end
13
+ end
14
+
15
+ def initialize ( watcher :)
16
+ @watched_dirs = nil
17
+ @watcher_class = watcher
18
+ @watcher = nil
19
+ end
20
+
21
+ def clear_cache_if_necessary
22
+ watched_dirs = dirs_to_watch
23
+ if watched_dirs != @watched_dirs
24
+ @watched_dirs = watched_dirs
25
+ @watcher = @watcher_class . new ( [ ] , watched_dirs ) do
26
+ clear_cache
27
+ end
28
+ @watcher . execute
29
+ else
30
+ @watcher . execute_if_updated
31
+ end
32
+ end
33
+
34
+ def clear_cache
35
+ ActionView ::LookupContext ::DetailsKey . clear
36
+ end
37
+
38
+ private
39
+
40
+ def dirs_to_watch
41
+ fs_paths = all_view_paths . grep ( FileSystemResolver )
42
+ fs_paths . map ( &:path ) . sort . uniq
43
+ end
44
+
45
+ def all_view_paths
46
+ ActionView ::ViewPaths . all_view_paths . flat_map ( &:paths )
47
+ end
48
+ end
49
+ end
Original file line number Diff line number Diff line change @@ -6,12 +6,6 @@ module ActionView
6
6
class Digestor
7
7
@@digest_mutex = Mutex . new
8
8
9
- module PerExecutionDigestCacheExpiry
10
- def self . before ( target )
11
- ActionView ::LookupContext ::DetailsKey . clear
12
- end
13
- end
14
-
15
9
class << self
16
10
# Supported options:
17
11
#
Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ class Railtie < Rails::Engine # :nodoc:
81
81
initializer "action_view.per_request_digest_cache" do |app |
82
82
ActiveSupport . on_load ( :action_view ) do
83
83
unless ActionView ::Resolver . caching?
84
- app . executor . to_run ActionView ::Digestor :: PerExecutionDigestCacheExpiry
84
+ app . executor . to_run ActionView ::CacheExpiry :: Executor . new ( watcher : app . config . file_watcher )
85
85
end
86
86
end
87
87
end
Original file line number Diff line number Diff line change @@ -280,6 +280,8 @@ def extract_handler_and_format_and_variant(path)
280
280
281
281
# A resolver that loads files from the filesystem.
282
282
class FileSystemResolver < PathResolver
283
+ attr_reader :path
284
+
283
285
def initialize ( path , pattern = nil )
284
286
raise ArgumentError , "path already is a Resolver class" if path . is_a? ( Resolver )
285
287
super ( pattern )
You can’t perform that action at this time.
0 commit comments