Skip to content

Add dev caching toggle / server options#20961

Merged
kaspth merged 1 commit into
rails:masterfrom
ccallebs:add-dev-mode-caching
Aug 5, 2015
Merged

Add dev caching toggle / server options#20961
kaspth merged 1 commit into
rails:masterfrom
ccallebs:add-dev-mode-caching

Conversation

@ccallebs

Copy link
Copy Markdown
Contributor

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

Fixes #18875.

Comment thread railties/test/commands/server_test.rb Outdated

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

kaspth commented Jul 22, 2015

Copy link
Copy Markdown
Contributor

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

@ccallebs

Copy link
Copy Markdown
Contributor Author

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

Comment thread railties/lib/rails/commands/server.rb Outdated

Copy link
Copy Markdown
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
Copy Markdown
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

dhh commented Jul 23, 2015

Copy link
Copy Markdown
Member

Awesome. Thanks for working on this!

Comment thread railties/CHANGELOG.md Outdated

Copy link
Copy Markdown
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

kaspth commented Jul 25, 2015

Copy link
Copy Markdown
Contributor

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

@kaspth

kaspth commented Jul 25, 2015

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

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

@ccallebs

Copy link
Copy Markdown
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

kaspth commented Jul 30, 2015

Copy link
Copy Markdown
Contributor

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

kaspth commented Jul 30, 2015

Copy link
Copy Markdown
Contributor

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

@kaspth

kaspth commented Aug 4, 2015

Copy link
Copy Markdown
Contributor

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

@ccallebs

ccallebs commented Aug 4, 2015

Copy link
Copy Markdown
Contributor Author

@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

kaspth commented Aug 4, 2015

Copy link
Copy Markdown
Contributor

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

ccallebs commented Aug 5, 2015

Copy link
Copy Markdown
Contributor Author

@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

kaspth commented Aug 5, 2015

Copy link
Copy Markdown
Contributor

@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

sdhull commented Nov 10, 2021

Copy link
Copy Markdown
Contributor

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.

4 participants