From d22574e1bb948cf140b43d1112e93b4562337484 Mon Sep 17 00:00:00 2001 From: Jared Norman Date: Sun, 24 Mar 2019 09:42:37 -0700 Subject: Sort config options I just like any list with more than half a dozen things to be sorted. --- lib/super_good/solidus_taxjar.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/super_good/solidus_taxjar.rb b/lib/super_good/solidus_taxjar.rb index 818947d..00c3ad5 100644 --- a/lib/super_good/solidus_taxjar.rb +++ b/lib/super_good/solidus_taxjar.rb @@ -12,20 +12,20 @@ module SuperGood module SolidusTaxJar class << self attr_accessor :discount_calculator - attr_accessor :test_mode attr_accessor :exception_handler - attr_accessor :taxable_address_check - attr_accessor :shipping_tax_label_maker attr_accessor :line_item_tax_label_maker + attr_accessor :shipping_tax_label_maker + attr_accessor :taxable_address_check + attr_accessor :test_mode end self.discount_calculator = ::SuperGood::SolidusTaxJar::DiscountCalculator - self.test_mode = false self.exception_handler = ->(e) { Rails.logger.error "An error occurred while fetching TaxJar tax rates - #{e}: #{e.message}" } - self.taxable_address_check = ->(address) { true } - self.shipping_tax_label_maker = ->(shipment, shipping_tax) { "Sales Tax" } self.line_item_tax_label_maker = ->(taxjar_line_item, spree_line_item) { "Sales Tax" } + self.shipping_tax_label_maker = ->(shipment, shipping_tax) { "Sales Tax" } + self.taxable_address_check = ->(address) { true } + self.test_mode = false end end -- cgit v1.2.3 From 347272600825af3119454c51dd1e43be5dd9bfbc Mon Sep 17 00:00:00 2001 From: Jared Norman Date: Sun, 24 Mar 2019 09:51:44 -0700 Subject: Make cache key configurable Some stores may want to more aggressively cache the responses, preferring fewer requests to more accurate results. --- CHANGELOG.md | 4 ++++ lib/super_good/solidus_taxjar.rb | 10 ++++++++++ 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 -- cgit v1.2.3 From 65e678ddcd32d6c5edc59c86b77800d86a5cdba3 Mon Sep 17 00:00:00 2001 From: Jared Norman Date: Sun, 24 Mar 2019 10:02:07 -0700 Subject: Make cache duration configurable --- CHANGELOG.md | 2 +- lib/super_good/solidus_taxjar.rb | 2 ++ lib/super_good/solidus_taxjar/tax_calculator.rb | 5 ++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index edb0d68..3b8690f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## master -- Make response cache key configurable. +- Made response cache key and cache duration configurable. ## v0.8.0 diff --git a/lib/super_good/solidus_taxjar.rb b/lib/super_good/solidus_taxjar.rb index 7033501..ba4ff48 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_duration attr_accessor :cache_key attr_accessor :discount_calculator attr_accessor :exception_handler @@ -20,6 +21,7 @@ module SuperGood attr_accessor :test_mode end + self.cache_duration = 3.hours self.cache_key = ->(order) { APIParams.order_params(order).transform_values do |value| case value diff --git a/lib/super_good/solidus_taxjar/tax_calculator.rb b/lib/super_good/solidus_taxjar/tax_calculator.rb index e6ac0a2..0ddd50f 100644 --- a/lib/super_good/solidus_taxjar/tax_calculator.rb +++ b/lib/super_good/solidus_taxjar/tax_calculator.rb @@ -116,7 +116,10 @@ module SuperGood def cache if !Rails.env.test? - Rails.cache.fetch(cache_key, expires_in: 3.hours) { yield } + Rails.cache.fetch( + cache_key, + expires_in: SuperGood::SolidusTaxJar.cache_duration + ) { yield } else yield end -- cgit v1.2.3 From ba8dc647da8c69428a2dfb3a136a59bbb8cacdd7 Mon Sep 17 00:00:00 2001 From: Jared Norman Date: Sun, 24 Mar 2019 10:02:44 -0700 Subject: Bump to v0.9.0 --- CHANGELOG.md | 2 ++ lib/super_good/solidus_taxjar/version.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b8690f..47b07aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## master +## v0.9.0 + - Made response cache key and cache duration configurable. ## v0.8.0 diff --git a/lib/super_good/solidus_taxjar/version.rb b/lib/super_good/solidus_taxjar/version.rb index a8fd65c..bd3ad9c 100644 --- a/lib/super_good/solidus_taxjar/version.rb +++ b/lib/super_good/solidus_taxjar/version.rb @@ -1,5 +1,5 @@ module SuperGood module SolidusTaxJar - VERSION = "0.8.0" + VERSION = "0.9.0" end end -- cgit v1.2.3