以下の内容はhttps://hyottokoaloha.hatenablog.com/entry/2016/05/06/020050より取得しました。


Railsアプリケーションを6倍速くしてから更に5倍速くした

hyottokoaloha.hatenablog.com

500msから更に5倍速くした

やった事

Rails.cache

Rails.cache使ってモデルメソッドの結果をキャッシュに入れました。

def hoge
cache_variable = Rails.cache.read("#{column_name}_cache")
  if cache_variable.nil?
    #重い処理してarrayに入れる
    Rails.cache.write("#{column_name}_cache", array.to_a, expires_in: 24.hour)
    array
  else
    cache_variable
  end
end

こうしたらアクセスしてもsql文が発行されなくなった。

最終的に

Completed 200 OK in 3271ms (Views: 53.9ms | ActiveRecord: 2300.6ms)
↓
Completed 200 OK in 112ms (Views: 15.4ms | ActiveRecord: 4.9ms)

29倍速くなりました。

キャッシュ便利すぎて怖いので何かデメリットをご存知の方がいれば教えて下さい。

参考




以上の内容はhttps://hyottokoaloha.hatenablog.com/entry/2016/05/06/020050より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14