Rails fragment caching not working locally - ruby-on-rails

I've added the following at the top of my index.html.haml:
- cache do
content
And as far as I can see, the content is not cached. My server output shows that when I reload the page, it still fetches all the info from the database again.
I haven't tried on live as I don't want to push anything before it's 100% working. What am I doing wrong? Am I not understanding how it's supposed to work? I've set the config.action_controller.perform_caching = true.

cache_store configures which cache store to use for Rails caching so you need to specify that
You need to set cache store in general config.
config.cache_store = xyz,abc # PUT THIS
Options that you can set:
:memory_store, :file_store, :mem_cache_store

Related

`method_missing': undefined method `cache' for #<Rails::Application::Configuration:

I am having the mentioned error on a rails project, after I added the following line of code in the config/environments/development.rb
config.cache.store = :dalli_store
I am working on a personal project using Rails 4.2, installed on OS X 10.7.5. Also memcached 1.4.5 is installed an running in my computer. I don't understand why this is happening. I want to use cache.store on my project but, I don't know how to solve this problem. Any help will be well received !
Please change:
config.cache.store = :dalli_store
to
config.cache_store = :dalli_store
Guide says Cache Stores
Rails provides different stores for the cached data created by action and fragment caches.
Configuration
You can set up your application's default cache store by calling config.cache_store = :dalli_store
Alternatively, you can call ActionController::Base.cache_store outside
of a configuration block.
You can access the cache by calling Rails.cache
The cache store has a bounded size specified by the :size options to the initializer (default is 32Mb).
If you need to increase that then like below
config.cache_store = :dalli_store, { size: 64.megabytes }
And finally you written config.cache.store = :dalli_store that is wrong because Rails guide says config.cache_store
If you need to know more about Rails 4.2 Caching then please visit Rails official document about Cach here
Hope it helps

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

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

how does rails cache my pages in spite of perform_caching being false?

as you now, in development mode the "perform_caching" configuration in action_controller is set to false by default. this configuration is in config/environments/development.rb:
config.action_controller.perform_caching = false
i tried a bunch of difference views(both html and json) and after a refresh, the requests were all 304(cached). so what is perform_caching doing here exactly?
by the way, i didn't use any caching method such as (cache , stale , cache_page , cache_action , ...) and maybe this is why perform_caching is not working. so how is this caching implemented?

How to set Rails Cache log level separately?

I use a pretty old rails version which is 2.3.2 because of legacy project.
I set global log_level to :debug in our rails app. But since we also use Rails.cache the log file are full of annoying lines such as
Cache read: ...
Cache miss: ...
I want to just suppress these but not affect other 'more useful' info such as SQL logging.
How to do that?
Well, after initializing your cache store (in the example below, I use memory store) in your specific environment.rb file, you can redirect cache_store's log to a separate file and also tweak the logger level:
config.cache_store = ActiveSupport::Cache::MemoryStore.new(:expires_in => 5.minutes)
config.cache_store.logger = Logger.new("#{Rails.root}/log/#{ENV['RAILS_ENV']}_cache.log")
config.cache_store.logger.level = Logger::INFO
In addition to that, the cache store has a method called silence! that will turn off the logger :-|
config.cache_store.silence!

RAILS: Stop Caching for Testing

We are load testing an application. I just want to check how it behaves if it hits database every time a request is made. I want to stop all type of caching temporarily. Is there a to do this?
Thanks,
Imran
In development mode by default no caching performed. You can adjust caching in config/environments/development.rb and config/environments/production.rb
E.g., there're following values in the production config by default
config.cache_classes = true
config.action_controller.perform_caching = true
config.action_view.cache_template_loading = true

Resources