From 2b9212814fd500f61c49b79f5482decc509234e1 Mon Sep 17 00:00:00 2001 From: Reegan Viljoen Date: Tue, 15 Oct 2024 21:28:07 +0200 Subject: [PATCH] fix cacahe implementatation to work with all methods --- lib/view_component/base.rb | 4 +--- lib/view_component/cache_on.rb | 27 --------------------------- 2 files changed, 1 insertion(+), 30 deletions(-) delete mode 100644 lib/view_component/cache_on.rb diff --git a/lib/view_component/base.rb b/lib/view_component/base.rb index d47e17447..f16b5921f 100644 --- a/lib/view_component/base.rb +++ b/lib/view_component/base.rb @@ -50,7 +50,7 @@ def config attr_accessor :__vc_original_view_context - # TODO + # Compoents can have a cache key that is used to cache the rendered output. # # @return [String] def cache_key @@ -333,8 +333,6 @@ def __vc_render_in_block_provided? defined?(@view_context) && @view_context && @__vc_render_in_block end - - # TODO def __vc_render_template(rendered_template) # Avoid allocating new string when output_preamble and output_postamble are blank if output_preamble.blank? && output_postamble.blank? diff --git a/lib/view_component/cache_on.rb b/lib/view_component/cache_on.rb deleted file mode 100644 index 938bc9355..000000000 --- a/lib/view_component/cache_on.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -module ViewComponent::CacheOn - extend ActiveSupport::Concern - - included do - def cache_key - @vc_cache_args = vc_cache_args.map { |method| send(method) } if defined?(vc_cache_args) - - @vc_cache_key = Digest::MD5.hexdigest(@vc_cache_args.join) - end - end - - class_methods do - def cache_on(*args) - define_method(:vc_cache_args) { args } - end - - def call - if cache_key - Rails.cache.fetch(cache_key) { super } - else - super - end - end - end -end