render_async icon indicating copy to clipboard operation
render_async copied to clipboard

alternative caching strategy

Open koenhandekyn opened this issue 8 years ago • 1 comments

just a suggestion that might be added to the documentation.

i'm using render async with this pattern: i'm rendering the existing partials by adding paths and methods that just render the existing partials, while making use of the existing request caching mechanisms. the key advantage is that it's not taking cache memory on the server but it's using the client side (or in between) HTTP caches. for full correctness, fragment caching is complimentary in the general case, but in general the HTTP caching should not be forgotten and can bring extra 'relief' for the server.

  def _details
    authorize @node, :show?
    if (stale?(@node)) # makes the browser cache subsequent requests
      readonly = (current_user == nil) || (current_user.can_write? == false)
      render partial: 'details', locals: {node: @node, node_structure: @node_structure, readonly: readonly}
    end
  end

koenhandekyn avatar Oct 24 '17 15:10 koenhandekyn

Great suggestion @koenhandekyn, thanks for sharing this.

If you're up for it, you can make a PR that adds this recipe to documentation :)

Let me know in the comment or by creating a PR 🍻

nikolalsvk avatar Oct 30 '17 08:10 nikolalsvk