Rails 3.2.3でレコードキャッシュをアクティブにする方法
stocks_controller.rb:
def index
@stocks = Rails.cache.read custom_cache_path(@res.uuid, Const::ACTIVE_STOCKS)
if @stocks.blank?
@stocks = Stock.only_active_stocks(params[:restaurant_id])
Rails.cache.write custom_cache_path(@res.uuid, Const::ACTIVE_STOCKS), @stocks
end
end
def show
@stocks = Rails.cache.read custom_cache_path(@res.uuid, Const::ACTIVE_STOCKS)
if @stocks.blank?
@stocks = Stock.only_active_stocks(params[:restaurant_id])
Rails.cache.write custom_cache_path(@res.uuid, Const::ACTIVE_STOCKS), @stocks
end
end
show アクション キャッシュへの要求が nil を返すのはいつですか?