Rails 4 cache: How to disable default caching for particular controller action or view?

1.5k Views Asked by At

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?

1

There are 1 best solutions below

0
omnikron On

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