Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #44 from hooktstudios/cache-fixes-3

Cache fixes 3
  • Loading branch information...
commit ae766658438d6cfc68c73f6f68d2f811a9def08a 2 parents 7c44b7e + 682bd9f
@jumph4x jumph4x authored
Showing with 18 additions and 11 deletions.
  1. +18 −11 app/models/spree/calculator/active_shipping/base.rb
View
29 app/models/spree/calculator/active_shipping/base.rb
@@ -36,7 +36,7 @@ def compute(object)
:city => addr.city,
:zip => addr.zipcode)
- rates = Rails.cache.fetch(cache_key(order)) do
+ rates_result = Rails.cache.fetch(cache_key(order)) do
order_packages = packages(order)
if order_packages.empty?
{}
@@ -45,7 +45,11 @@ def compute(object)
end
end
- rate = rates[self.class.description]
+
+ raise rates_result if rates_result.kind_of?(Spree::ShippingError)
+ return nil if rates_result.empty?
+ rate = rates_result[self.class.description]
+
return nil unless rate
rate = rate.to_f + (Spree::ActiveShipping::Config[:handling_fee].to_f || 0.0)
@@ -65,11 +69,12 @@ def timing(line_items)
:state => (addr.state ? addr.state.abbr : addr.state_name),
:city => addr.city,
:zip => addr.zipcode)
- timings = Rails.cache.fetch(cache_key(order)+"-timings") do
- timings = retrieve_timings(origin, destination, packages(order))
+ timings_result = Rails.cache.fetch(cache_key(order)+"-timings") do
+ retrieve_timings(origin, destination, packages(order))
end
- return nil if timings.nil? || !timings.is_a?(Hash) || timings.empty?
- return timings[self.description]
+ raise timings_result if timings_result.kind_of?(Spree::ShippingError)
+ return nil if timings_result.nil? || !timings_result.is_a?(Hash) || timings_result.empty?
+ return timings_result[self.description]
end
@@ -111,9 +116,9 @@ def retrieve_rates(origin, destination, packages)
message = e.to_s
end
- Rails.cache.write @cache_key, {} #write empty hash to cache to prevent constant re-lookups
-
- raise Spree::ShippingError.new("#{I18n.t(:shipping_error)}: #{message}")
+ error = Spree::ShippingError.new("#{I18n.t(:shipping_error)}: #{message}")
+ Rails.cache.write @cache_key, error #write error to cache to prevent constant re-lookups
+ raise error
end
end
@@ -132,8 +137,10 @@ def retrieve_timings(origin, destination, packages)
else
message = re.message
end
- Rails.cache.write @cache_key+'-', {} #write empty hash to cache to prevent constant re-lookups
- raise Spree::ShippingError.new("#{I18n.t(:shipping_error)}: #{message}")
+
+ error = Spree::ShippingError.new("#{I18n.t(:shipping_error)}: #{message}")
+ Rails.cache.write @cache_key+"-timings", error #write error to cache to prevent constant re-lookups
+ raise error
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.