2

I'm trying to fragment cache a static portion of my site, but it doesn't seem to be working at all. I've set up config/application.rb with the following:

config.action_controller.perform_caching = true
config.cache_store = :dalli_store

In my view, I have this:

<% cache 'cache_key' do %>
  <!-- cached markup -->
<% end %>

I don't see anything in my logs about saving the fragment to cache or retrieving it on subsequent page loads. I've also tried using the default Rails :file_store caching. I know that the cache store is working because using Rails.cache.fetch works properly.

How can I get this to work?

mrdziuban
  • 749
  • 3
  • 11
  • 23

2 Answers2

7

In Rails 5:

$ rails dev:cache
Development mode is now being cached.

Activates caching in development environment.

Artem P
  • 5,198
  • 5
  • 40
  • 44
  • 1
    Since this question is about Rails 4.2, you may want to leave this as a comment instead.. (Also, it's not really clear what your code is supposed to do in the context of this question) – Grisha Levit Feb 01 '17 at 00:29
3

You are probably working in your development environment. in /config/environments/development change:

# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false

TO

# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = true

The development settings might override the other settings. Make sure memcache is installed and running. If there is something wrong it should show up in the console.

Stephan
  • 3,679
  • 3
  • 25
  • 42