summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--lib/super_good/solidus_taxjar.rb2
-rw-r--r--lib/super_good/solidus_taxjar/tax_calculator.rb5
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