Rails 4.2 fragment caching isn't working - ruby-on-rails

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?

In Rails 5:
$ rails dev:cache
Development mode is now being cached.
Activates caching in development environment.

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.

Related

Why incorrect controller file nesting is not error in development?

I have the following in my config routes:
...
scope module: :public do
...
scope module: :doctor do
get 'vets/new', to: 'vets#new'
...
end
end
So, the nesting is: public -> doctor -> vets.
By accident, I put vets controller into a public folder (app/controllers/public/vets_controller.rb), wrapped it into Public module. And also put an appropriate view: app/views/public/vets/new.html.slim.
This stuff is working correctly on my local machine, but after the deployment process, I get 404 error.
How can I turn this check on in development mode? I need to know about this type of issues on the development stage.
Why do you think it even works on my local machine?
All the documentation that include scope module: "etc" only ever use 1 level of nesting.
Using 2 levels of scope nesting wasn't how it was intended to be used. It's a bug that Rails doesn't notice these errors in development.
To get the errors that you want, change some of the configuration options in your development.rb file. Notice how they are different from your production.rb file.
# config/environments/development.rb
Rails.application.configure do
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# more code
end
To
# config/environments/production.rb
Rails.application.configure do
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot.
# This eager loads most of Rails and your application in memory,
# allowing both threaded web servers and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# more code
end

Rails fragment caching not working locally

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

Can't update my view pages at Rails application

How can I fix this problem. Please teach me how to solve this....
First, I had tried to use page cache on my web app. But, it doesn't run well. That was not so good. So, I updated to get rid of page cache. After that, my app's view page that had page cache could not be updated.
below is a my config/environment/development.rb
KaguShop::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
#caching for objects
#config.cache_store = :mem_cache_store
end
And, after I edited my cache setting, I tried this command.
※and of course, I reopen the browser.
rails console
Rails.cache.clear
try ctrl+shift+delete on browser to clear cache.
To perform caching config.action_controller.perform_caching should be set to true
before update you must do something like expire_page :action => action_name
Ex:
def update
expire_page :action => profile
...........
end
I gathered information about caching at 2 places other day. Check them here and here
OMG....
This is the answer of this question.
I didnt know this rails's structure...
After removing caches_page cached sites are still not updated

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?

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