如何在 Rails 3.2.3 中激活记录缓存
库存控制器.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
对显示操作缓存的请求何时返回 nil?