You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Darius Rus <da...@gmail.com> on 2009/03/23 15:12:45 UTC

[users@httpd] How to avoid caching on apache (with tomcat in back-end)?

Hi,

I have an issue related to caching on apache server (my setup is
Apache/2.2.11 (Win32) in front of tomcat/6.0.18 using mod_jk/1.2.27)

I have a dynamic (JSP) page with a form that can be submitted that contains:

response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
response.setHeader("Pragma","no-store, no-cache, must-revalidate"); //HTTP 1.0
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
response.setDateHeader ("Expires", -1); //prevents caching at the proxy server

I've added this to avoid caching, so that after the form is submitted
and the user clicks on browser "back" button the form is not displayed
from cache.

When I'm accessing this page directly from tomcat (bypassing apache
server) I get the correct behavior, the page is retrieved from the
server when "back" button is pressed, however when I'm accessing the
page through apache a cached version is displayed.

I've checked if I have cache enabled on apache server and I don't, all
cache related modules are not loaded:

#LoadModule cache_module /usr/lib/apache2/modules/mod_cache.so
#LoadModule disk_cache_module /usr/lib/apache2/modules/mod_disk_cache.so
#LoadModule file_cache_module /usr/lib/apache2/modules/mod_file_cache.so
#LoadModule mem_cache_module /usr/lib/apache2/modules/mod_mem_cache.so

Any suggestions why I have this behavior? And how to solve the issue?

Thanks in advance,
Darius

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How to avoid caching on apache (with tomcat in back-end)?

Posted by Matus UHLAR - fantomas <uh...@fantomas.sk>.
On 23.03.09 16:12, Darius Rus wrote:
> I have a dynamic (JSP) page with a form that can be submitted that contains:
> 
> response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
> response.setHeader("Pragma","no-store, no-cache, must-revalidate"); //HTTP 1.0

only no-cache is used in the Pragma: header, the others belong to
Cache-Control: header

> response.addHeader("Cache-Control", "post-check=0, pre-check=0");
> response.setDateHeader ("Expires", -1); //prevents caching at the proxy server
> 
> I've added this to avoid caching, so that after the form is submitted
> and the user clicks on browser "back" button the form is not displayed
> from cache.

"Cache-Control: must-revalidate" with Expires: should be enough for this.

> I've checked if I have cache enabled on apache server and I don't, all
> cache related modules are not loaded:
> 
> #LoadModule cache_module /usr/lib/apache2/modules/mod_cache.so
> #LoadModule disk_cache_module /usr/lib/apache2/modules/mod_disk_cache.so
> #LoadModule file_cache_module /usr/lib/apache2/modules/mod_file_cache.so
> #LoadModule mem_cache_module /usr/lib/apache2/modules/mod_mem_cache.so

These only affect caching on apache's side, the browser and intermediate
proxies still may cache the content themselves.
-- 
Matus UHLAR - fantomas, uhlar@fantomas.sk ; http://www.fantomas.sk/
Warning: I wish NOT to receive e-mail advertising to this address.
Varovanie: na tuto adresu chcem NEDOSTAVAT akukolvek reklamnu postu.
My mind is like a steel trap - rusty and illegal in 37 states. 

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How to avoid caching on apache (with tomcat in back-end)?

Posted by André Warnier <aw...@ice-sa.com>.
Darius Rus wrote:
[...]
I don't know the answer, but before you possibly go off in wrong 
directions, I suggest you really make double-sure of what is happening, 
in more precise ways than just what the browser shows.
For example, Firefox with the LiveHttpHeaders or HttpFox add-ons, will 
show the exact HTTP headers sent by the browser, and returned by the 
server in both cases (direct connection to Tomcat or through Apache).
(For IE, Fiddler offers similar functionality).
Alternatively, if you have a workstation or server with perl installed, 
you can use the command-line lwp-request, which with the appropriate 
command-line parameters will also show the request and response headers.

Note that I am not saying that your symptoms are not correct, I am just 
trying to save you potentially some loss of time.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How to avoid caching on apache (with tomcat in back-end)?

Posted by Brian Mearns <me...@gmail.com>.
On Mon, Mar 23, 2009 at 10:12 AM, Darius Rus <da...@gmail.com> wrote:
> Hi,
>
> I have an issue related to caching on apache server (my setup is
> Apache/2.2.11 (Win32) in front of tomcat/6.0.18 using mod_jk/1.2.27)
>
> I have a dynamic (JSP) page with a form that can be submitted that contains:
>
> response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
> response.setHeader("Pragma","no-store, no-cache, must-revalidate"); //HTTP 1.0
> response.addHeader("Cache-Control", "post-check=0, pre-check=0");
> response.setDateHeader ("Expires", -1); //prevents caching at the proxy server
>
> I've added this to avoid caching, so that after the form is submitted
> and the user clicks on browser "back" button the form is not displayed
> from cache.
>
[clip]

If you're able to determine (or still strongly suspect) that the
browser is really behaving as you originally thought, check to see if
your browser is actually recognizing the page as expired, but is
checking back with a HEAD to see if it's actually been modified. If
any part of your server or server-side script is putting in a
Last-Modified or Etag headher, then the browser could be validating
against these and determining it does not actually need to update. If
this is happening, it should show up in your server's access logs as
an additional access.

Also, check your server's logs to find out what version of the HTTP
protocol your browser is requesting with; this will help you track
down where your problem is. It's most likely 1.1, but you never know,
and 1.0 client's are notoriously unfettered when it comes to caching.

Out of curiosity, where did the post-check and pre-check come from?
I'm not familiar with those (non-standard) cache-control directives.

-Brian

-- 
Feel free to contact me using PGP Encryption:
Key Id: 0x3AA70848
Available from: http://pgp.mit.edu/

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org