This project is archived and is in readonly mode.

#2095 ✓resolved
Gregg Pollack

Adding public options to client-side caching

Reported by Gregg Pollack | February 27th, 2009 @ 07:14 PM | in 2.x

If you want to use Proxy caches with Rails, you have to modify the "Cache-Control" header to have the public keyword. This is defaulted to private in rails, which is fine, but the syntax to set cache-control to public isn't too pretty:


expires_in 10.minutes, :private => false, :public => true
 
fresh_when :last_modified => @user.updated_at.utc
headers['Cache-Control'] = 'public'
 
fresh_when :etag => @user
headers['Cache-Control'] = 'public'

Here is code (with tests) that allows you to do:


expires_in 10.minutes, :public => true
 
fresh_when :last_modified => @user.updated_at.utc, :public => true
 
fresh_when :etag => @user, :public => true

I've also added some additional tests for expires_at that seemed to be missing from the code. For additional explanation, see the Advanced HTTP Caching Screencast.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages