Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dev caching toggle / server options #20961

Merged
merged 1 commit into from Aug 5, 2015
Merged

Add dev caching toggle / server options #20961

merged 1 commit into from Aug 5, 2015

Conversation

ccallebs
Copy link
Contributor

Taken extensively from @Sonopa's PR (#19091). Added ability to specify caching on server start.

Fixes #18875.

end

def test_caching_with_option
args = ["-C"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could potentially cause some confusion, as there is already a -c option. I think it should be changed, I just didn't have a notion of what it should be.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be easier to grasp as just --toggle-caching - maybe we don't even need a shorthand?

Though I'm still ¯_(ツ)_/¯ about the server options in general.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaspth I'm ambivalent about the whole thing as well, just added it as it seemed there was support in the previous PR. I'll go with the hivemind on it.

@kaspth
Copy link
Contributor

kaspth commented Jul 22, 2015

If you change your pull request description to say "Fixes #18875" the original issue will be closed if this is merged 😄

@ccallebs
Copy link
Contributor Author

@kaspth Thank you for the suggestions -- I'll implement them this evening!

@@ -67,6 +69,7 @@ def start
print_boot_information
trap(:INT) { exit }
create_tmp_directories
create_cache_file if options[:cache]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like setting --perform-caching once never removes the file and leaves caching on all the time. Let's fix that 😄

@ccallebs
Copy link
Contributor Author

@kaspth I implemented most of your suggestions. Instead of having a --toggle-cache option on the server, I chose to remove caching if the option wasn't specified. It made more sense to me that way, as a user will know when they start their server whether or not they would like to temporarily cache.

@dhh
Copy link
Member

dhh commented Jul 23, 2015

Awesome. Thanks for working on this!

@@ -1,3 +1,11 @@
* Make enabling or disabling caching in development mode possible with rake dev:cache

Running rake dev:cache will create or remove tmp/caching-dev.txt. When this file exists config.action_controller.perform_caching will be set to true in config/environments/development.rb.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Break the lines at 80 chars 😄

@kaspth
Copy link
Contributor

kaspth commented Jul 25, 2015

Alright, once the final comment has been addressed, ping me. Remember to keep it to one commit, then I'll gladly merge 😁

@kaspth
Copy link
Contributor

kaspth commented Jul 25, 2015

I just realized there's a scenario we have to make sure doesn't happen. Maybe I'm misunderstanding something, but what happens when rake dev:cache reboots the server?

There's no --perform-caching flag provided, so won't the caching be turned off again?

I'd like a test that checks against this.

@ccallebs
Copy link
Contributor Author

@kaspth That's a good point! I'll write the test and if it fails find a workaround.

@ccallebs
Copy link
Contributor Author

@kaspth The easiest way to fix the above is just by defaulting the server to create the cache file if options are passed. Otherwise, default to the last rake dev:cache command. I've pushed the changes up.

Additionally, I couldn't find any concrete examples of tests that check the server start. Could you point me toward some (if they exist)?

@kaspth
Copy link
Contributor

kaspth commented Jul 30, 2015

Honestly, that --perform-caching setting doesn't make sense anymore. If I passed an option on one server start and then removed it for the next server start I wouldn't expect it to still be in effect.

Looking back to @pixeltrix's original suggestion I see --perform-caching takes an argument, which is exactly how we should do it.

Perhaps --perform-caching=true to enable and --perform-caching=false to disable could do it. There's probably a separate issue with what values can be truthy and falsy on a command line interface, but we can deal with that later.

@kaspth
Copy link
Contributor

kaspth commented Jul 30, 2015

@ccallebs Sorry, I'm not aware of any tests checking the server start.

@kaspth
Copy link
Contributor

kaspth commented Aug 4, 2015

@ccallebs are you up for adding an argument to --perform-caching as mentioned here: #20961 (comment)?

@ccallebs
Copy link
Contributor Author

ccallebs commented Aug 4, 2015

@kaspth Absolutely! Sorry, I've been busy and haven't been able to sit down and do it. I'll try to tackle it this evening.

@kaspth
Copy link
Contributor

kaspth commented Aug 4, 2015

Cool, glad to hear it 😄

Taken from @Sonopa's commits on PR #19091.

Add support for dev caching via "rails s" flags.

Implement suggestions from @kaspth.

Remove temporary cache file if server does not have flags.

Break at 80 characters in railties/CHANGELOG.md

Remove ability to disable cache based on server options.

Add more comprehensive options: --dev-caching / --no-dev-caching
@ccallebs
Copy link
Contributor Author

ccallebs commented Aug 5, 2015

@kaspth After looking at the OptionParser documentation, I ended up changing the name of the keyword. (http://docs.ruby-lang.org/en/2.2.0/OptionParser.html)

Now, it would be rails s --dev-caching or rails s --no-dev-caching. It seemed to be the way to define boolean arguments according to that class. If we want to change it to perform-caching=[true|false] I'm completely fine with that, but it looked like this followed OptionParser conventions more closely.

kaspth added a commit that referenced this pull request Aug 5, 2015
Add dev caching toggle / server options
@kaspth kaspth merged commit 2d00aa7 into rails:master Aug 5, 2015
@kaspth
Copy link
Contributor

kaspth commented Aug 5, 2015

@ccallebs Thanks ❤️

@ccallebs ccallebs deleted the add-dev-mode-caching branch August 5, 2015 21:13
ghiculescu added a commit to ghiculescu/rails that referenced this pull request Dec 23, 2020
On a new Rails app, [`config/development.rb`](https://github.com/rails/rails/blob/master/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt#L19) is set up to support [`rails dev:cache`](rails#20961).

This PR explains how to enable caching in development in https://guides.rubyonrails.org/caching_with_rails.html, replacing the old advice that looks like it came before rails#20961.
@sdhull
Copy link
Contributor

sdhull commented Nov 10, 2021

Apologies for resurrecting an ancient PR thread but... wouldn't it make more sense to have the task called rails dev:toggle-cache or something like that? I was assuming rails dev:cache would turn on caching and I came looking for a way to turn it off (rails dev:nocache or something).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants