Before asking my question, i read document configurigng Rails Applications
and i still don't know reason why my view cached is not working stably. In my case, after updating the codes in views, sometimes i don't need restart application server(Thin) and the views is reloaded with the modifications Seen that the controllers and models are not reloaded, so my app crashes ... Strange, this problem is not always there it's not stably. sometimes all is ok.
my config production mode like this:
...
# Code is not reloaded between requests
config.cache_classes = true
...
From the documentation, i learned that if i set true to config.cache_classes, i don't need to set true to config.action_view.cache_template_loading it will follow cache_classes configuring.
I think that cache_classes controls if all classes, modules and views templates will reload for each request. am i right ? any suggestion is welcome.
Related
I am working on rails application , in which i am using ruby 1.9.2 and rails 3.0.8. My application is running quite fine in development environment, which includes creating tables from the application and accessing them.
But when i start my application in production environment in which caching is enabled, every thing is working fine , i am not able to access the table which i am creating using my application. I am able to access these tables after restarting the server, which is a pain.
I am searching for a way where i can clear the cache whenever new table get created, can you please help me to clear the cache dynamically.
Thanks
Naveen Kumar Madipally
The one workaround would be to do this in your environments/production.rb (which is not at all recommended on production)
config.cache_classes = false
this will decrease your performance in production but what you can do is fo to production.rb file and check the blow lines
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
i guess it will solve your problem
There are abstractions for that in ActionDispatch::Reloader : it's what's used in development environment to reload classes.
So basically, you would need to run :
ActionDispatch::Reloader.cleanup!
ActionDispatch::Reloader.prepare!
I'm not sure it would be such a good idea, though, as you can't expect which code (yours or from gems) does things that are supposed to happen only once.
Couldn't you use STI rather than dynamicly creating tables ?
I'm trying to speed up my web fronted by caching classes in development,
My::Application.configure do
config.cache_classes = true
end
but I would like to manually reload classes using guard if a file in my model or lib changes.
So the question is this: without restarting my local server, how can i manually trigger a class cache refresh?
Update
You can use reload!
don't know why i didn't think of that sooner
Even I don't answer your raw question, this link should answer your goal as a whole.
In a nutshell:
Reload Rails code in development mode only when change is detected
I am working on an existing Rails 2.3.x application, So I was working on it and it was a messy code with great difficulty I was able to run the application. But now for every small change in one of my controller it is expecting me to restart my serer otherwise the changes are not reflecting back, Let's take an example scenario here, Let's just say in one of the before_filter method I just added a puts statement on top of the method and it was not printing in the log, after I restart the server it is printing, Can some one please let me know if I am missing something here.
What environment are you using?
The default environment is 'development', where the code is reloaded on each request. However, this behaviour can be overwritten in the config file.
To be sure that the code is reloaded, add this into your config/development.rb file:
# 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 webserver when you make code changes.
config.cache_classes = false
If you are using config.threadsafe! It needs to be present before config.cache_classes=false as threadsafe makes cache_classes true again, following link would make it more clear. here
Maybe you have don't flush. The log system in Rails use a BufferedLogger. So need a flush to be print. Try a default logger.
In my rails app. I am using link_to_function to bring an ajax tabs in one page.Everything works fine in Moazilla and other browsers. But in IE the tabs are not loading only when the server is started in production mode(doesn't matter whether it's webrick or mongrel). In development mode everything is fine. So I figured out that the issue was with one line
config.cache_classes = true
in app/config/environments/production.rb
when I changed the above code to
config.cache_classes = false
everything works fine.
So I assume caching causes problem in Rails.
When I Googled about this I found many have the issues with caching.
So my question is
1) is there any other fix for this?
2) Does this fix (config.cache_classes = false) causes any performance issues. If then how to overcome that?
Any comments and suggestions are welcome.
Techno_log
cache_classes is setting that tells web server if it should reload whole app for each request. More precisely:
"Whether or not classes should be cached (set to false if you want application classes to be reloaded on each request)"
(from: http://api.rubyonrails.org/classes/Rails/Configuration.html)
Setting cache_classes to false will have big impact on your app performance.
However, your problem, most likely, is not related to this setting. I suggest that you take look at IE cache (i.e. try clearing out cache), maybe some caching headers you are setting when generating page, etc.
Also the fact that all other browsers get good response from server means that web server is generating good response.
What are the difference between three modes in rails like:-
In development mode, Rails reloads models each time a browser sends in a request,
so the model will always reflect the current database schema.
EDIT
I was asking about the other differences. I mentioned one i was looking for other list of differences...!!
It comes down to performance and stability. In production mode, model are cached in memory, meaning that once they have been read once, the files don't have to be read again, bringing an obvious speed benefit. This means that if you were to alter the ruby file (eg app/models/page.rb) where a model is defined, this change would not be picked up until the next reload.
By default, the following line is found in config/environments/production.rb:
config.cache_classes = true
The assumption is that when you're in production mode, you won't be changing your code other than via a release or deployment. If you want to clear the cache, you need to restart the application.
The development environment will reload your models each time it receives a request. This is controlled by the following default line in config/environments/development.rb:
config.cache_classes = false
In terms of the 'third' mode, I presume you mean test mode. This also caches models by default (see config/environments/test.rb), again with the assumption that you won't be altering your codebase mid-way through a test run.
Btw, it's not just models - I'm pretty sure that this setting encompasses any classes found within the 'app' directory. In addition, you will find that, even in development mode, classes located elsewhere in the application (eg 'lib') can not be changed without restarting the application.
The behavior of the three modes is configured in:
rails_app/config/environments/[production|development|test].rb
So, it depends on your configuration how the three modes are different.