Proposed Cache API extensions

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 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

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.

<% 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