RAILS: Stop Caching for Testing - ruby-on-rails

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

Related

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

Rails 4.2 fragment caching isn't working

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.

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 Server needs restart every time I make changes? why?

Every time I change anything in controller's or in models, I have to restart the server for it to take effect.But that wasn't always the case, it used to work normally before, when I changed anything, but i don't know what happened now ?
My Rails version is 3.2.11
In my development environment file i have set config.cache_classes = false.
Please help..
My development.rb file is as follows
Testapp::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
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# 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
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
end
I have got the answer..
After adding following line in my config/environments/development.rb file my issue has been resolved.
config.reload_classes_only_on_change = false
start your server using below command in console
rails server -e development
if not started then give your rails version and which sever you use for run rails application.
more Configuration
modify your config/environments/development.rb file to:
config.serve_static_assets = false
An additional situation where this can come up is in a virtualized environment where the files are being edited on the host operating system, and the guest operating system's file event manager doesn't generate events for file changes.
A solution for this situation is to comment out the following line in config/environments/development.rb:
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
Thus giving:
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
This forces rails to actually check file modification times instead of expecting to get filesystem events.
There is a good note for VirtualBox users, posted as comment by user Ninjaxor:
For Vagrant/ virtual box users, there's a bug where if the host clock
and guest clock are out of sync, it borks rails' reloader.
https://github.com/rails/rails/issues/16678
The file Vagrantfile you find in a directory like this:
.../ruby/gems/sass-3.4.22/vendor/listen
There you have to add this:
# Sync time every 5 seconds so code reloads properly
config.vm.provider :virtualbox do |v|
v.customize ["guestproperty", "set", :id, "--timesync-threshold", 5000]
end
Thanks to user axsuul on GitHub!
I noticed that setting
config.cache_classes = false
is what did the trick for me.

Resources