Just wanted to run this by a few people to get some feedback. At the moment, fragment cache (as indeed Rails.cache) calls often look a bit like this: <% cache("some_namespace_#{@record.id}") do %> I was thinking cache should take multiple arguments, which would be joined with an underscore, like this: <% cache(:namespace, @record.id) do %> Looks a bit nicer. This wouldn''t stop old cache calls (with a string) from working. What do you think? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
You may want it to accept *args and join them all, possibly by implicitly calling .to_param on them. i.e. cache(@forum, @topic, @post) do to uniquely cache a particular set of associated objects On Thu, Dec 4, 2008 at 1:23 PM, Alex MacCaw <maccman@gmail.com> wrote:> > Just wanted to run this by a few people to get some feedback. > > At the moment, fragment cache (as indeed Rails.cache) calls often look > a bit like this: > <% cache("some_namespace_#{@record.id}") do %> > > I was thinking cache should take multiple arguments, which would be > joined with an underscore, like this: > <% cache(:namespace, @record.id) do %> > > Looks a bit nicer. This wouldn''t stop old cache calls (with a string) > from working. > > What do you think? > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Could also go with more of a rails convention and have... <% cache_for(@record) do %> --> "user_45_cache" which would equate to something like dom_id where it uses the types class and the object id as part of the namespace. The namespace param could be used as well and it would work similar to dom_id as well where it appends to whatever the usual default is. <% cache_for(@record, :namespace) do %> --> "user_45_cache_namespace" Just some thoughts off the top of my head. On Thu, Dec 4, 2008 at 12:23 PM, Alex MacCaw <maccman@gmail.com> wrote:> > Just wanted to run this by a few people to get some feedback. > > At the moment, fragment cache (as indeed Rails.cache) calls often look > a bit like this: > <% cache("some_namespace_#{@record.id}") do %> > > I was thinking cache should take multiple arguments, which would be > joined with an underscore, like this: > <% cache(:namespace, @record.id) do %> > > Looks a bit nicer. This wouldn''t stop old cache calls (with a string) > from working. > > What do you think? > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
> <% cache_for(@record) do %> --> "user_45_cache" which would equate to > something like dom_id where it uses the types class and the object id > as part of the namespace.This already works if the first argument to #cache is an Array. Elements are joined with #to_param. Additionally, if any element in the collection responds to #cache_key, it will be called. All AR objects respond to #cache_key: Topic.first.cache_key #=> "topics/1-20081129070634" So, if you do something like cache([@topic, @post]), you''ll get a key like: "topics/1-20081129070634/posts/1-20050211193200" See ActiveSupport::Cache.expand_cache_key /Jeff --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---