title: Ruby on Rails 4 - Cache Partials from Model
body: <p>I am working on an app where certain pages take longer to load because of the views are a list of X to 1000 table rows. Each row has Y columns that take time to construct.</p>
  
  <p>Right now, the first time the user hits the page with the table rows, it takes say N seconds. However, on refreshes, the page loads very quickly b/c of the cache.</p>
  
  <p>I would like preload these partials and store it in my cache from a Rails model when the user logs in so if the user visits the page with the table rows, it will already be cached.</p>
  
  <p>I have attempted to do this by calling a Sidekiq job when the user logins and cache the partial via a call below however even though I used the same cache key, it doesn't seem to be pulling from the same cache?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>view = ActionView::Base.new(ActionController::Base.view_paths, {})
  view.render(...)</code></pre>
  </div>
  </div>
  </p>
  
  <p>Any suggestions? I do know it is because when I call from the above, the fragment cache logic does not generate the digest. I ended up solving the issue by using Rails.cache fetch calls within a helper.</p>