11# frozen_string_literal: true
22
3- require 'set'
4- require 'view_component/cache_registry'
3+ require "set"
4+ require "view_component/cache_registry"
5+ require "view_component/cache_digestor"
56
67module ViewComponent ::Cacheable
78 extend ActiveSupport ::Concern
@@ -25,7 +26,7 @@ def view_cache_dependencies
2526 def __vc_render_cacheable ( rendered_template )
2627 if __vc_cache_dependencies != [ :format , :__vc_format ]
2728 ViewComponent ::CachingRegistry . track_caching do
28- template_fragment ( rendered_template )
29+ template_fragment ( rendered_template )
2930 end
3031 else
3132 __vc_render_template ( rendered_template )
@@ -43,12 +44,12 @@ def template_fragment(rendered_template)
4344 end
4445
4546 def read_fragment ( rendered_template )
46- Rails . cache . fetch ( view_cache_dependencies )
47+ Rails . cache . fetch ( component_digest )
4748 end
4849
4950 def write_fragment ( rendered_template )
5051 content = __vc_render_template ( rendered_template )
51- Rails . cache . fetch ( view_cache_dependencies ) do
52+ Rails . cache . fetch ( component_digest ) do
5253 content
5354 end
5455 content
@@ -60,6 +61,11 @@ def combined_fragment_cache_key(key)
6061 cache_key . compact!
6162 cache_key
6263 end
64+
65+ def component_digest
66+ component_name = self . class . name . demodulize . underscore
67+ ViewComponent ::CacheDigestor . digest ( name : component_name , format : format , finder : @lookup_context , dependencies : view_cache_dependencies )
68+ end
6369 end
6470
6571 class_methods do
0 commit comments