6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Jbuilderでつくったフラグメントキャッシュを削除する

Last updated at Posted at 2016-02-28
json.cache! "v1.person", expires_in: 10.minutes do
  json.extract! @person, :name, :age
end

Jbuilderでこんな感じでフラグメントキャッシュをつくったあとに、このキャッシュを明示的に削除したいと思ってRails.cache.deleteにキーをそのまま渡すと

Rails.cache.delete("v1.person") # => nil

キャッシュにヒットしませんでした。

ソースコードを調べたところ、どうやらJbuilderの内部でjbuilder/という名前空間が渡されたキーに追加されているみたいです。

というわけでキャッシュを削除したいときは先頭にjbuilder/を追加するとうまくいきます。

Rails.cache.delete("jbuilder/v1.person") # => true
6
6
0

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
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?