views:

85

answers:

2

I'm using the below headers on my web site but I'm running into a problem. The first time I visit my site for the day I don' tsee my ACP link. There are also instances where information is in our database that only registered members can create, but the form is still being loaded for non-logged in users so information is being created with the member_id field being 0.

I think the problem is that the cached file is staying on the proxy cache too long. Perhaps I missed something or misunderstood the caching technique I'm using.

Any advice anyone can provide would be appreciated.

  if ($currentMember->isLoggedIn()) {
   $this->cachePermission = 'private';
  } else {
   $this->cachePermission = 'public';
  }
  $this->tru->header->set('Pragma', array(
   $this->cachePermission
  ));
  $this->tru->header->set('Cache-Control', array(
   $this->cachePermission,
   'no-cache',
   'max-age=300',
   's-maxage=300',
   'must-revalidate'
  ));

Update

I'm mainly trying to get the Back button to work in the viewer's browser. I don't want any other caching aside from that.

+2  A: 

I would recommend not allowing the page to be cached at all if it's going to change based on whether or not the user is logged on.

Cache-Control: no-store, must-revalidate
Expires: 0

If that's too extreme, I would at least suggest always using Cache-Control: private and never allowing it to be stored in the proxy cache. In my experience, allowing the proxy to cache it will just cause trouble when different users see different things.

Updated:

In my experience, finding a middle ground like that can be difficult if you want it to operate the same in all major browsers. You might try starting with just Cache-Control: private, must-revalidate and going from there.

One other thing that might help is using an ETag header based on the page's state and which user is logged in. Once the header is added, pecl_http provides some useful functions like http_cache_etag() for sending a 304/Not modified response to the browser so it knows to load from the cache instead.

Jason
The headers of the page contain a network bar which has all of your logged in features. So every page on the site maintains whether the user is logged in or not. I really just want when the user hits back or forward in the browser for it to load the cache.
Webnet
I've adjusted the headers as you suggested with just private/must-revalidate and am going to see how that works.
Webnet
It doesn't quite seem to be working. I can't quite determine what's up. Whenever I first visit the page it has my proper username and is thus detecting my login properly. It shows the "My Account" link with the options to log out and such. However as an Author on my site, I only see the link Author CP after the initial page is shown.
Webnet
A: 

I've seen FireFox get very aggressive with it's caching. You can tell this is happening when you type in an artificial query string to your URI and you get fresh results.

?asdf=1

Is often what I tack on the end when diagnosing browser madness.

memnoch_proxy