LoginSignup
13
11

More than 5 years have passed since last update.

Railsでキャッシュにあったら返す、なかったらセットするやつ

Last updated at Posted at 2015-02-20

if文書いてあったらreadなかったらwriteする、とか書く必要がありません。
fetch一発でいけます、楽ちん過ぎてゆとり化が捗ります。


Rails.cache.fetch(
  "today_average_reponse_time_#{Time.now.to_date.to_s}", 
  expires_in: 1.hour, compress:true) do
  Report.today_average_reponse_time
end

消したりして動作チェックしたいときはこれ。


Rails.cache.delete("today_average_reponse_time_2015-02-20")

13
11
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
11