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

Use digest cache in development. #20384

Merged
merged 2 commits into from
Jul 20, 2015
Merged

Use digest cache in development. #20384

merged 2 commits into from
Jul 20, 2015

Conversation

kaspth
Copy link
Contributor

@kaspth kaspth commented May 30, 2015

Fixes #20361

Avoid computing the same fragment digest many times when looping over templates, and
cut down on logging noise.

The cache is cleared on every request, so there's no chance of stale templates being served.

cc @dhh @rafaelfranca @britto

@kaspth kaspth self-assigned this May 30, 2015
@kaspth kaspth added this to the 5.0.0 milestone May 30, 2015
@kaspth
Copy link
Contributor Author

kaspth commented May 30, 2015

Ya, it's kinda late here and I think I missed that we should wrap around fragment_for to capture what's written to the cache and not just the fragment name. c/d @dhh?

I should add a test for the caching writing and reading. Possibly even one for the reduced log output.

For glory and all the XP!

@dhh
Copy link
Member

dhh commented Jun 1, 2015

I haven't actually dug into this part of the code in a long time. @rafaelfranca could you vet this?

@rafaelfranca
Copy link
Member

Ya, it's kinda late here and I think I missed that we should wrap around fragment_for to capture what's written to the cache and not just the fragment name. c/d

c

@@ -42,6 +42,16 @@ class Railtie < Rails::Railtie # :nodoc:
end
end

initializer "action_view.fragment_name_cache" do |app|
ActiveSupport.on_load(:action_view) do
if Rails.env.development?
Copy link
Member

Choose a reason for hiding this comment

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

I think we should check consider_all_requests_local.

@dhh
Copy link
Member

dhh commented Jun 26, 2015

Hey @kaspth had any chance to consider this further?

@kaspth
Copy link
Contributor Author

kaspth commented Jun 26, 2015

Sorry, I've totally sweat this out. I'll take a look this weekend 👍

Kasper

On 26. jun. 2015 15.29 +0200, David Heinemeier Hanssonnotifications@github.com, wrote:

Hey@kaspth(https://github.com/kaspth)had any chance to consider this further?


Reply to this email directly orview it on GitHub(#20384 (comment)).

@dhh
Copy link
Member

dhh commented Jun 26, 2015

Rocking. Thanks man!

On Fri, Jun 26, 2015 at 3:45 PM, Kasper Timm Hansen <
notifications@github.com> wrote:

Sorry, I've totally sweat this out. I'll take a look this weekend 👍

Kasper

On 26. jun. 2015 15.29 +0200, David Heinemeier Hansson<
notifications@github.com>, wrote:

Hey@kaspth(https://github.com/kaspth)had any chance to consider this
further?


Reply to this email directly orview it on GitHub(
#20384 (comment)).


Reply to this email directly or view it on GitHub
#20384 (comment).

@@ -98,7 +98,7 @@ module CacheHelper
# <%# Template Dependency: todolists/todolist %>
# <%= render_sortable_todolists @project.todolists %>
#
# The pattern used to match these is <tt>/# Template Dependency: (\S+)/</tt>,
# The pattern used to match these is /# Template Dependency: ([^ ]+)/,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unintended change from a rebase, I'll fix it on the next push.

@kaspth kaspth force-pushed the per-request-cache branch 2 times, most recently from 07de57b to 810013d Compare June 26, 2015 20:04
get '/customers/1'
end

assert write_not_called
Copy link
Member

Choose a reason for hiding this comment

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

Since it is per request should not this be false since other request was made and the cache was cleaned?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha, doh. Thanks 😄

@kaspth
Copy link
Contributor Author

kaspth commented Jun 28, 2015

@rafaelfranca I'm really stumped on getting these tests to work 😢

It's all coming up black magic, and I have no idea what's going on.

For some reason the initializers aren't run. However, if I added this in cache_helper.rb:

class ActionView::Base
  mattr_accessor(:per_request_fragment_cache) { ActiveSupport::Cache::MemoryStore.new }
end

They were run! Do you have any idea why? 😄

The next problem was that app.config.consider_all_requests_local was false even though I added it to the config. Can you spot if I've done it wrong?

@rafaelfranca
Copy link
Member

Weird. I'll debug in my machine

@kaspth
Copy link
Contributor Author

kaspth commented Jul 12, 2015

@dhh I finally got everything up and running here. I reread your original description of the problem and realized I'd been trying to solve the wrong thing 😅

Anyway, the cache now captures generated digests which I think is what you want.

Also I looked at ActionView::Digestor which seems to already have a cache. Can that fill your use case? 😄

@dhh
Copy link
Member

dhh commented Jul 12, 2015

Hey, hey. Yeah, all I wanted was that the cache we're already using in production for template digests to be used on a per-request basis in development. So the first lookup of a template within a request in development is computed, all subsequent lookups are not. 👍

Avoid computing the same fragment digest many times when looping over templates.

The cache is cleared on every request so template changes are still picked up.
@kaspth
Copy link
Contributor Author

kaspth commented Jul 18, 2015

@dhh Boom, got it 👍. Way easier once I figured out there was already a cache.

I'm closing and reopening for Travis to run.

@kaspth kaspth closed this Jul 18, 2015
@kaspth kaspth reopened this Jul 18, 2015
@kaspth kaspth changed the title Add per request fragment name cache. Use digest cache in development. Jul 19, 2015
@dhh
Copy link
Member

dhh commented Jul 20, 2015

Badabing! Awesome. Thanks!

dhh added a commit that referenced this pull request Jul 20, 2015
Use digest cache in development.
@dhh dhh merged commit 068865a into rails:master Jul 20, 2015
@kaspth kaspth deleted the per-request-cache branch July 20, 2015 11:20
@rafaelfranca rafaelfranca modified the milestones: 5.0.0 [temp], 5.0.0 Dec 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Digest cache should be per-request in development mode
3 participants