Merge pull request #3404 from luisramos0/2-0-disable-cache

[Spree Upgrade] Add checkbox to disable products cache
This commit is contained in:
Pau Pérez Fabregat
2019-03-05 14:51:11 +01:00
committed by GitHub
7 changed files with 99 additions and 37 deletions

View File

@@ -27,19 +27,21 @@ module OpenFoodNetwork
private
def cached_products_json
if Rails.env.production? || Rails.env.staging?
Rails.cache.fetch("products-json-#{@distributor.id}-#{@order_cycle.id}") do
begin
uncached_products_json
rescue ProductsRenderer::NoProducts
nil
end
return uncached_products_json unless use_cached_products?
Rails.cache.fetch("products-json-#{@distributor.id}-#{@order_cycle.id}") do
begin
uncached_products_json
rescue ProductsRenderer::NoProducts
nil
end
else
uncached_products_json
end
end
def use_cached_products?
Spree::Config[:enable_products_cache?] && (Rails.env.production? || Rails.env.staging?)
end
def uncached_products_json
ProductsRenderer.new(@distributor, @order_cycle).products_json
end