Src
Src

Reputation: 5482

Cache expires_in not working

I'm trying to cache data like so:

def index
    Rails.cache.fetch("someCache", expires_in: 12.hours) do
      'someContent'
    end
    raise Rails.cache.fetch("someCache").inspect
end

and everything is ok (it returns someContent) until i remove block which sets the value (it's already set for 12 hours, right?) and refresh the page:

def index
    raise Rails.cache.fetch("someCache").inspect
end

returns nil

Upvotes: 3

Views: 892

Answers (2)

ecoologic
ecoologic

Reputation: 10420

The actual command for Rails 5 is:

rails dev:cache

This command will toggle activation, so if you run it again it will disable development caching.

You will read or these two confirmations:

Development mode is now being cached.

Development mode is no longer being cached.

More info here.

Upvotes: 5

Src
Src

Reputation: 5482

Resolved:

In order to enable caching in development envirounment, you have to create tmp/caching-dev.txt in your application root path.

Upvotes: 1

Related Questions