I have a quite a big jpg image file and few css files, and these are not going to change for every reload but every time it is loading the full imgae instead of caching in the browser, I tried changing the config like config.action_controller.perform_caching = true etc but nothing seems to help. Is there a way to do that?
This worked for me in my production.rb:
config.serve_static_assets = true
config.static_cache_control = "public, max-age=2419200"
That is 4 weeks which I figure is good enough.
Related
First of all I don't know if this is a bug or not. Until now I've been using this command in rails development.rb environment config so the box detects changes on my files:
config.reload_classes_only_on_change = false
But now, with Rails 5.2 and Active Storage that command makes the server a lot slower, and the images takes from 10 to 40sec to load.
Is it a bug? There is another way to make the vagrant/rails detect changes on my files without making me reload the server every time I change something?
Solution:
After questioning the owner of the box I've been using, he gave me this alternative that works:
At the bottom of the config/environments/development.rb I did this change:
Find this line at the bottom of the file and comment out:
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
Then add this line:
config.file_watcher = ActiveSupport::FileUpdateChecker
So it looks like this:
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
config.file_watcher = ActiveSupport::FileUpdateChecker
Now it works properly and I do not have to use this command anymore:
config.reload_classes_only_on_change = true
Best regards!
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
I'm deploying a site using capistrano to DigitalOcean, and I'm stuck with a problem where some images don't display. I say some, because some do display properly (with the right assets/... URL) while some images in the same div don't display (instead trying to access some images/... path).
The weird part is these images are all in the same folder (assets/images), used in the same each loop, all using the <%= image_tag %> tag.
During deployment, rake assets:precompile always succeeds and there's no visible error.
And lastly, here's a part of my production.rb file:
config.serve_static_assets = false
config.assets.compile = true
config.assets.digest = true
config.assets.version = '1.0'
If you need any other code snippets, let me know and I'll provide them asap.
EDIT:
Changing config.serve_static_assets = false to config.serve_static_assets = true doesn't change the result in any way.
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?
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