Semi-dynamic page and action cache

I am trying to figure out the best way to handle caching in a fairly
unique scenario. I’ve read through the various caching posts, but
nothing really matches what I am trying to do.

Let’s assume there are two models, company and site, and each has a
string (short_name) that will be used for routing. So we can do
either of the following:
http(s)://{company.short_name}.{mydomain}.com/{site.short_name}, or
http(s)://{mydomain}.com/{company.short_name}/{site.short_name}

Both of these are mapped to a single controller and action that
figures out what to render based on the various attributes in the
models. But, once it renders, I’d like to cache the content if the
site is set to use caching. I’d like to cache the action rather than
the site if the site requires authentication. And in some cases, no
caching should be used. When I try to do this in my controller
action, a page gets cached, but it’s empty and it isn’t used. If I do
this after I render the view, the page does get written to the cache,
but then rails is not picking it up and still performs all the logic
then re-writes to the cache. Is there any way around this?

if @site.cache_page?
    unless @site.requires_authentication?
      cache_page
    else
      cache_action
    end
  end

I realize that normally one would cache the action in the class def,
but I can’t really do that, since I don’t want to always return the
cached page anytime that action is called in the controller, and I
don’t want to have to have a controller and action for every site.