Sunday, 15 July 2012

fragment caching - How to handle key based expiration of collections if there is no parent model in Rails 4.0? -



fragment caching - How to handle key based expiration of collections if there is no parent model in Rails 4.0? -

since action , page caches , sweepers removed rails 4.0, started utilize cache_digests in rails 3.2 application, since i'm suffering whole manual expiration nightmare.

but after reading tutorials (how key-based cache expiration works, cache digests, #387 cache digests, ...) couldn't find way handle views there no parent object provide time stamp or similar.

for illustration works flawlessly, if document , todolist utilize touch alternative on project association.

# app/views/projects/show.html.erb <% cache @project %> <%= render @project.documents %> <%= render @project.todolists %> <% end %>

but index action?

# app/views/projects/index.html.erb <% cache ??? %> <% @projects.each |project| %> ... <% end %> <% end %>

of course of study utilize arbitrary key project_index , expire on alter of project model, require sweeper or observer , getting rid of them including explicit expiration 1 of major reasons key based expiration.

what rails 4.0 way this?

just this:

# app/views/projects/index.html.erb <% cache @projects %> <% @projects.each |project| %> ... <% end %> <% end %>

the projects collection create cache key, changes in collection in terms of order or objects create different key.

it have limitations if views showing info relating projects lower level associations, can dealt with.

ruby-on-rails fragment-caching ruby-on-rails-4

No comments:

Post a Comment