Header page caching
I'm using the below headers o开发者_运维百科n 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.
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.
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.
精彩评论