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

Rendering a template out of Controller scope does not append digest hash of template to cache_key #546

Open
blotto opened this issue Apr 24, 2014 · 2 comments

Comments

@blotto
Copy link

blotto commented Apr 24, 2014

I'm using Rails 4.0.2, and want to background rendering of objects for cache warming, prior to a Controller action ever being hit for certain APIs.

When rendering a template from a Controller action, I get the expected cache actions showing the below cache keys. In this case, the template's cache digest is d30440d18014c72014a05319af0626f7

Cache read: rabl/activities/26600-20140423170223588554000//hash/d30440d18014c72014a05319af0626f7 
Cache generate: rabl/activities/26600-20140423170223588554000//hash/d30440d18014c72014a05319af0626f7 
Cache write: rabl/activities/26600-20140423170223588554000//hash/d30440d18014c72014a05319af0626f7

When calling Rabl::Render out of the Controller's scope I get a different cache_key, basically without the temaplte digest appended to the end.

Rabl::Renderer.new('api/v2/activities/show_no_root', @activity, {:view_path => 'app/views', :format => :json, :scope => self}).render
Cache read: rabl/activities/26600-20140423170223588554000//hash
Cache generate: rabl/activities/26600-20140423170223588554000//hash
Cache write: rabl/activities/26600-20140423170223588554000//hash

I realize this is a scoping issue, but its not clear what the scope should be in the cache warming use case. Passing self be it the Model, Observer, or some Helper class doesn't provide the scope necessary for the template digest to be appended to the cache_key. When passing the Controller through this does work as expected, but this is not available during the attempt to warm the cache through a background process. Maybe this approach is totally incorrect?

@blotto
Copy link
Author

blotto commented Apr 29, 2014

I could not find a solution with Rabl::Render to warm a cache, but am able to use this method as a background process effectively. I think this is a bit too heavy, and still think there is a more elegant solution out there with Rabl::Render.

#example
cache_warmer( :api_v2_expensiveapi_url, args_array , params_hash)
#method
def cache_warmer( url_helper, args, params={},method='get')
     if method == 'get'
       session = ActionDispatch::Integration::Session.new(Rails.application)
       session.get(session.send(url_helper, *args), params)
     end
end

kept issue open as I think this is worth a discussion on how or why not Rabl::Render can provide this

@blotto blotto closed this as completed Apr 29, 2014
@blotto blotto reopened this Apr 29, 2014
@nguyenmighty
Copy link
Contributor

nguyenmighty commented Jul 7, 2016

I'm running into the same issue here. Rails haml has the ability to skip_digest, and I think the same option should be available for RABL caching as well.

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

No branches or pull requests

2 participants