diff options
author | Jared Norman <jared@super.gd> | 2019-03-24 09:51:44 -0700 |
---|---|---|
committer | Jared Norman <jared@super.gd> | 2019-03-24 09:53:14 -0700 |
commit | 347272600825af3119454c51dd1e43be5dd9bfbc (patch) | |
tree | 29d5005bd66b99012fed867c7d409f1eea01af39 | |
parent | d22574e1bb948cf140b43d1112e93b4562337484 (diff) |
Make cache key configurable
Some stores may want to more aggressively cache the responses,
preferring fewer requests to more accurate results.
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | lib/super_good/solidus_taxjar.rb | 10 | ||||
-rw-r--r-- | lib/super_good/solidus_taxjar/tax_calculator.rb | 8 |
3 files changed, 15 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index b704dee..edb0d68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## master + +- Make response cache key configurable. + ## v0.8.0 - Increased response caching time to 3 hours. diff --git a/lib/super_good/solidus_taxjar.rb b/lib/super_good/solidus_taxjar.rb index 00c3ad5..7033501 100644 --- a/lib/super_good/solidus_taxjar.rb +++ b/lib/super_good/solidus_taxjar.rb @@ -11,6 +11,7 @@ require "super_good/solidus_taxjar/discount_calculator" module SuperGood module SolidusTaxJar class << self + attr_accessor :cache_key attr_accessor :discount_calculator attr_accessor :exception_handler attr_accessor :line_item_tax_label_maker @@ -19,6 +20,15 @@ module SuperGood attr_accessor :test_mode end + self.cache_key = ->(order) { + APIParams.order_params(order).transform_values do |value| + case value + when Array, Hash then value.hash + else + value + end + end + } self.discount_calculator = ::SuperGood::SolidusTaxJar::DiscountCalculator self.exception_handler = ->(e) { Rails.logger.error "An error occurred while fetching TaxJar tax rates - #{e}: #{e.message}" diff --git a/lib/super_good/solidus_taxjar/tax_calculator.rb b/lib/super_good/solidus_taxjar/tax_calculator.rb index e8e12f4..e6ac0a2 100644 --- a/lib/super_good/solidus_taxjar/tax_calculator.rb +++ b/lib/super_good/solidus_taxjar/tax_calculator.rb @@ -123,13 +123,7 @@ module SuperGood end def cache_key - APIParams.order_params(order).transform_values do |value| - case value - when Array, Hash then value.hash - else - value - end - end + SuperGood::SolidusTaxJar.cache_key.(order) end def exception_handler |