Topic: [SOLVED] Action caching with pagination and authentication

I am starting to implement caching in a situation that requires separate caches between visitors and logged in users. I planned to use a solution explained on the RailsCasts to use different cache directories:


caches_action :index, :cache_path => :index_cache_path.to_proc, :layout => false

def index_cache_path
  if logged_in?
    '/private/welcome'
  else
    '/public/welcome'
  end
end


However, I soon realized that my will_paginate plugin will cause problems because action caching doesn't recognize the ?page parameter or anything else in the query string. So I added the page parameter to the cache path:

def index_cache_path
  p = ''
  p = params[:page] if params[:page] and params[:page] != 1
  if logged_in?
    '/private/welcome'+p
  else
    '/public/welcome'+p
  end
end

EDIT

I've moved this into production and the directory structure is working just fine. I also have added additional directories to the cache path depending on logged in status and it's working great.
This seems to be working great in my development environment, but I am still new to Rails and I haven't done any caching yet. Will I run into any problems, or should this work out fine?

Last edited by swese44 (2009-01-31 01:24:49)