I have a rails action which responds to requests in various formats including AJAX requests, for example:
def index
# do stuff
respond_to do |format|
format.html do
# index.html.erb
end
format.js do
render :update do |page|
page.replace_html 'userlist', :partial => "userlist", :object=>@users
page.hide('spinner')
page.show('pageresults')
end
end
end
end
I have set this action to cache using memcached using:
caches_action :index, :expires_in=>1.hour, :cache_path => Proc.new { |c| "index/#{c.params[:page]}/#{c.request.format}" }
This pattern seems to work fine for caching the HTML result but not for the JS result. The JS part always works fine when it is not coming from the cache. However when there is a cache hit, the page does not update.
What could cause this and what is the fix?
Update: digging into this more it looks like requests from the cache get mime type 'text/html' instead of 'text/javascript'. However I'm not sure how to fix this - is it a quirk of memcached? (Rails 2.3.2)