0

We have Rails 4.2 application running on production with the following configurations (cache related). And we have not implemented any caching technique so far (default setup).

config.action_controller.perform_caching = true

# Use a different cache store in production.
# config.cache_store = :mem_cache_store

I am having an issue with particular view which is not showing updated data accordingly.

Is there a way that I can disable fragment caching for particular view not in entire application?

Venkat Ch
  • 1,168
  • 2
  • 17
  • 37
  • 1
    Why not just remove your `cache some_model do` block from that view? – omnikron Aug 07 '17 at 12:38
  • @omnikron - no such code written in the view. Its I think Rails handles internally – Venkat Ch Aug 07 '17 at 12:40
  • No, you have to call `cache` explicitly, or your view will simply not be cached. If you don't have that anywhere, then none of your views are being cached, unless you are doing something else. See the [rails caching documentation](http://guides.rubyonrails.org/caching_with_rails.html#fragment-caching) for more info. Maybe you were confused by where it says "By default Rails provides fragment caching"? This just means that it is available by default – it doesn't actually implement it for you. – omnikron Aug 07 '17 at 12:43
  • @omnikron - Not really sure. But it worth to cross check. Thanks – Venkat Ch Aug 07 '17 at 13:00
  • 1
    @omnikron - You're right! I am really confused with the similar views in the application. Thanks for your comment for my dumb statements above :) – Venkat Ch Aug 07 '17 at 13:18
  • Haha, no worries! Glad to be able to help :) – omnikron Aug 07 '17 at 14:47

1 Answers1

1

TLDR: while caching can cause problems, it's worth verifying that you are actually using it before trying to fix it!

The simplest way to disable caching for a single view is also the most obvious (but potentially quite easy to miss):

Remove the cache model do block from inside your view.

Rails does not do any caching for you by default, so this will take care of it entirely. If you don't have a call to cache with a block inside your view, you are not using caching.

E.g:

Cached:

# app/views/something_important/show.html.haml
= cache something_important do
  = render_something_expensive

Not cached:

# app/views/something_important/show.html.haml
= render_something_expensive
omnikron
  • 2,211
  • 17
  • 30