如何在Rails的ActiveRecord的緩存3.2.3如何ActiveRecord的高速緩存中的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
什麼時候到表演動作緩存回報爲零的請求?
無論緩存命中/未命中,Rails.cache.fetch(id,find(id))是否總是命中DB? –