unepwcmc/SAPI

View on GitHub
app/controllers/api/v1/trade_plus_filters_controller.rb

Summary

Maintainability
A
0 mins
Test Coverage
class Api::V1::TradePlusFiltersController < ApplicationController
  respond_to :json

  CACHE_KEY_PREFIX = 'trade_plus_filters_with_locale_'

  def index
    cache_key = "#{CACHE_KEY_PREFIX}#{I18n.locale}"

    filters = Rails.cache.read(cache_key)
    if filters.nil?
      TradePlusFiltersWorker.perform_async(I18n.locale.to_s)
      head 409 # Cache not ready yet.
    else
      render :json => filters
    end
  end
end