diff options
author | andrea longhi <andrea@spaghetticode.it> | 2020-01-07 16:52:57 +0100 |
---|---|---|
committer | andrea longhi <andrea@spaghetticode.it> | 2020-01-14 09:44:59 +0100 |
commit | 0c11683822428495635e5acd2ec32c382f2ff261 (patch) | |
tree | 05c5169ef5ddee1ed125ef93eec9b60977a51ba2 /lib | |
parent | 37120896954c4f765c047c0ab0528dde1c41ae09 (diff) |
Add generic default cache_key proc
`SuperGood::SolidusTaxJar.cache_key` uses different `APIParams`
methods for calculating cache keys for different models.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/super_good/solidus_taxjar.rb | 5 |
1 files changed, 4 insertions, 1 deletions
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}" |