1
1
# frozen_string_literal: true
2
2
3
3
require "action_view"
4
+ require "view_component/cacheable"
4
5
require "active_support/configurable"
5
6
require "view_component/collection"
6
7
require "view_component/compile_cache"
@@ -34,6 +35,7 @@ def config
34
35
include ViewComponent ::Slotable
35
36
include ViewComponent ::Translatable
36
37
include ViewComponent ::WithContentHelper
38
+ include ViewComponent ::Cacheable
37
39
38
40
RESERVED_PARAMETER = :content
39
41
VC_INTERNAL_DEFAULT_FORMAT = :html
@@ -45,7 +47,7 @@ def config
45
47
delegate :content_security_policy_nonce , to : :helpers
46
48
47
49
# Config option that strips trailing whitespace in templates before compiling them.
48
- class_attribute :__vc_cache_dependencies , default : [ ]
50
+ # class_attribute :__vc_cache_dependencies, default: []
49
51
class_attribute :__vc_strip_trailing_whitespace , instance_accessor : false , instance_predicate : false
50
52
self . __vc_strip_trailing_whitespace = false # class_attribute:default doesn't work until Rails 5.2
51
53
@@ -110,14 +112,7 @@ def render_in(view_context, &block)
110
112
111
113
if render?
112
114
rendered_template = render_template_for ( @__vc_variant , __vc_request &.format &.to_sym ) . to_s
113
-
114
- if view_cache_dependencies . present?
115
- Rails . cache . fetch ( view_cache_dependencies ) do
116
- __vc_render_template ( rendered_template )
117
- end
118
- else
119
- __vc_render_template ( rendered_template )
120
- end
115
+ __vc_render_cacheable ( rendered_template )
121
116
else
122
117
""
123
118
end
@@ -263,15 +258,6 @@ def virtual_path
263
258
self . class . virtual_path
264
259
end
265
260
266
- # For caching, such as #cache_if
267
- #
268
- # @private
269
- def view_cache_dependencies
270
- return unless __vc_cache_dependencies . present? && __vc_cache_dependencies . any?
271
-
272
- __vc_cache_dependencies . map { |dep | send ( dep ) } . compact
273
- end
274
-
275
261
# For caching, such as #cache_if
276
262
#
277
263
# @private
@@ -324,15 +310,6 @@ def __vc_render_in_block_provided?
324
310
defined? ( @view_context ) && @view_context && @__vc_render_in_block
325
311
end
326
312
327
- def __vc_render_template ( rendered_template )
328
- # Avoid allocating new string when output_preamble and output_postamble are blank
329
- if output_preamble . blank? && output_postamble . blank?
330
- rendered_template
331
- else
332
- safe_output_preamble + rendered_template + safe_output_postamble
333
- end
334
- end
335
-
336
313
def __vc_content_set_by_with_content_defined?
337
314
defined? ( @__vc_content_set_by_with_content )
338
315
end
@@ -581,8 +558,6 @@ def render_template_for(variant = nil, format = nil)
581
558
child . instance_variable_set ( :@__vc_ancestor_calls , vc_ancestor_calls )
582
559
end
583
560
584
- child . __vc_cache_dependencies = __vc_cache_dependencies . dup
585
-
586
561
super
587
562
end
588
563
0 commit comments