user1204574
user1204574

Reputation: 43

Separate cache for logged in users

I currently have a website where I have roughly 20 separate pages. All pages have two versions... a version where the viewer has not logged in yet, along with a logged in version. The logged in version can vary quite differently from the non-logged in version... I was wondering if there is a simple way to tell browsers to 'invalidate' all cached pages for my domain when a user logs in or logs out.

Example: A non-logged in viewer visits many of the pages on my site, which causes their browser to cache all of these pages. Upon logon can I supply the user with a particular header which will make their browser to not use the cached version the next time the page loads? This needs to happen on both log-in and log-out.

Any tips or tricks would be super helpful, I am fairly new at caching... Thanks :)

Upvotes: 0

Views: 183

Answers (3)

shinronin
shinronin

Reputation: 193

ideally you wouldn't have separate pages to represent a user's logged-in state. that attribute of your application really belongs in the model not the view as it were. i imagine a logged-in user would never see the non-logged-in page via the controller, right? in which case i'd offer that it doesn't matter which page is cached and which isn't.

the following is the only way that occurs to me to do what you want, but it isn't pretty... if a user has logged in, but requests the non-logged-in page, expire the page (e.g. $q->header( -expires => 'now' )) and send the logged-in user to non-logged-in page. but, as above, i doubt you want to do that. you could reference a .js file that has js/ajax that detects such a scenario and then redirects the user back to the logged-in page.

you can see what an ordeal this could be. i'd suggest tightening up your application design such that this problem goes away. hopefully this was helpful. good luck!

Upvotes: 1

simbabque
simbabque

Reputation: 54323

Have a look at Force browser to clear cache. There are some promissing leads in there.

Otherwise, tell your users to Shift-Click the reload button. ;-)

Upvotes: 0

Dondi Michael Stroma
Dondi Michael Stroma

Reputation: 4800

No, you cannot tell the user's browser to un-cache pages. You could use different URLs for logged-in users than for logged out users (adding a query string would suffice), or, not allow caching of any of them in the first place.

Upvotes: 1

Related Questions