From 0c11683822428495635e5acd2ec32c382f2ff261 Mon Sep 17 00:00:00 2001 From: andrea longhi Date: Tue, 7 Jan 2020 16:52:57 +0100 Subject: Add generic default cache_key proc `SuperGood::SolidusTaxJar.cache_key` uses different `APIParams` methods for calculating cache keys for different models. --- lib/super_good/solidus_taxjar.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/super_good/solidus_taxjar.rb') diff --git a/lib/super_good/solidus_taxjar.rb b/lib/super_good/solidus_taxjar.rb index 8841acd..35d9155 100644 --- a/lib/super_good/solidus_taxjar.rb +++ b/lib/super_good/solidus_taxjar.rb @@ -26,7 +26,10 @@ module SuperGood end self.cache_duration = 3.hours - self.cache_key = ->(order) { APIParams.order_params(order).to_json } + self.cache_key = ->(record) { + record_type = record.class.name.demodulize.underscore + APIParams.send("#{record_type}_params", record).to_json + } self.discount_calculator = ::SuperGood::SolidusTaxJar::DiscountCalculator self.exception_handler = ->(e) { Rails.logger.error "An error occurred while fetching TaxJar tax rates - #{e}: #{e.message}" -- cgit v1.2.3