This project is archived and is in readonly mode.
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
-
Repository February 28th, 2009 @ 09:34 AM
- State changed from new to committed
(from [f2a32bd0dedf11021027e36cc2c99f97434cae17]) Added ability to pass in :public => true to fresh_when, stale?, and expires_in to make the request proxy cachable [#2095 state:committed]
Signed-off-by: David Heinemeier Hansson david@loudthinking.com http://github.com/rails/rails/co...
-
Johan Sørensen March 5th, 2009 @ 03:40 PM
- Assigned user set to DHH
Actually, the default Cache-Control seems to be no-cache now, when you use the conditional GET helpers at least. So this patch only helps if you only want public headers.
I'm thinking this patch should be reworked so that you can say :public => false. Which would make it set a Cache-Control header of private, instead of the no-cache default. This is useful if you want the clients to cache it, but not any proxies (assuming they play nice of course).
-
Johan Sørensen March 6th, 2009 @ 09:26 AM
Due to the fact that this commit introduces two test methods named test_expires_in_header this is never exposed in the tests.
Attached is a patch that renames one of the test methods and fixes the regression.
-
Pratik March 7th, 2009 @ 12:17 PM
- State changed from committed to open
-
Repository March 7th, 2009 @ 12:19 PM
- State changed from open to resolved
(from [c071123b3e2d6fd918dd7e419efe7429355445c2]) Ensure expires_in without a :public key sets the Cache-Control header to private. [#2095 state:resolved]
This fixes a regression introduced in f2a32bd0, which wasn't exposed due to two test methods having the same name.
Signed-off-by: Pratik Naik pratiknaik@gmail.com http://github.com/rails/rails/co...
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>
People watching this ticket
Attachments
Referenced by
- 2095 Adding public options to client-side caching (from [f2a32bd0dedf11021027e36cc2c99f97434cae17]) Added a...
- 2095 Adding public options to client-side caching (from [c071123b3e2d6fd918dd7e419efe7429355445c2]) Ensure ...