ETags are great for keeping the expensive stuff from executing over and over again, for example:
1 2 3 4 5
Will prevents some_really_expensive_operation from executing a second time when the user revisits the page if nothing in the object has changed. This works great on public pages but what if you have some expensive stuff on a page that requires authentication, or a page that the content changes when a user logs in? Fortunately, any object can be passed for the :etag option. We could create a method called authenticated_stale? and include the current user as follows in the application controller as follows:
1 2 3 4 5 6 7 8 9 10 11 12
And use authenticated_stale? for any page that requires authentication or where the content changes if you are authenticated as you would the stale? method. Make sure not to set the public option true on authenticated pages so they don’t get cached by proxy caches.