You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Alexander Barth <ba...@gmail.com> on 2015/07/14 09:22:54 UTC
[users@httpd] mod_cache issue if client send "If-Modified-Since" header.
Hi,
I have a python script which generates dynamic web pages and I want to use
mod_cache (and mod_cache_disk) to speed up the access to this page. The
python program uses the "If-Modified-Since", "Last-Modified" and the
"Cache-Control" headers. Revalidation is very fast for the python program,
therefore I set the response header
"Cache-Control" to "must-revalidate, max-age=5".
mod_cache works as expected as long as the client does not send itself the
"If-Modified-Since" header. In my tests below, mod_cache has cached version
of an URL (Last-Modified: Mon, 13 Jul 2015 07:33:49 GMT). The client tries
the revalidate a stale version (If-Modified-Since: Thu, 09 Jul 2015
20:26:45 GMT). The problem is that mod_cache ask to the python script if
the version from the 9 July can be revalidate (instead of its own more
recent version from the 13 July).
In my set-up, the client always send the "If-Modified-Since" header and
therefore the cached version from mod_cache is (almost) never used. I am
wondering if mod_cache should not try to revalidate to most recent version
(either from client or from cache).
I am using apache 2.4.10 (in a docker container based on ubuntu 15.04). The
tests I made were performed inside the container. For what is worth, I
include my configurations files (cache_disk.conf and 000-default.conf).
Any help would be greatly appreciated.
Thanks in advance,
Alex
## empty cache
# htcacheclean -p /var/cache/apache2/mod_cache_disk -r -l
1
## verify that cache is empty
# htcacheclean -p /var/cache/apache2/mod_cache_disk -A
## make first request
# curl --verbose '
http://localhost/Python/web/wms?request=GetCapabilities&service=WMS&version=1.3.0'
> out
* Connected to localhost (::1) port 80 (#0)
> GET /Python/web/wms?request=GetCapabilities&service=WMS&version=1.3.0
HTTP/1.1
> User-Agent: curl/7.38.0
> Host: localhost
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Tue, 14 Jul 2015 06:34:42 GMT
* Server Apache/2.4.10 (Ubuntu) is not blacklisted
< Server: Apache/2.4.10 (Ubuntu)
< Last-Modified: Mon, 13 Jul 2015 07:33:49 GMT
< Vary: Accept-Encoding
< X-Cache: MISS from 172.17.1.37
< X-Cache-Detail: "cache miss: attempting entity save" from 172.17.1.37
< Transfer-Encoding: chunked
< Content-Type: text/xml
<
## verify that first request is cached
# htcacheclean -p /var/cache/apache2/mod_cache_disk
-A
http://localhost:80/Python/web/wms?request=GetCapabilities&service=WMS&version=1.3.0
422 3697448 200 0 1436855683140502 1436855688140502 1436855682866721
1436855683140502 1 0
## make second request (after 5 seconds)
# curl --verbose '
http://localhost/Python/web/wms?request=GetCapabilities&service=WMS&version=1.3.0'
> out
* Hostname was NOT found in DNS cache
* Connected to localhost (::1) port 80 (#0)
> GET /Python/web/wms?request=GetCapabilities&service=WMS&version=1.3.0
HTTP/1.1
> User-Agent: curl/7.38.0
> Host: localhost
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Tue, 14 Jul 2015 06:34:59 GMT
* Server Apache/2.4.10 (Ubuntu) is not blacklisted
< Server: Apache/2.4.10 (Ubuntu)
< Last-Modified: Mon, 13 Jul 2015 07:33:49 GMT
< Vary: Accept-Encoding
< Cache-Control: must-revalidate, max-age=5
< X-Cache: REVALIDATE from 172.17.1.37
< X-Cache-Detail: "conditional cache hit: entity refreshed" from 172.17.1.37
< Content-Length: 3697448
< Content-Type: text/xml
<
## Yah! Cache is revalitated
# htcacheclean -p /var/cache/apache2/mod_cache_disk
-A
http://localhost:80/Python/web/wms?request=GetCapabilities&service=WMS&version=1.3.0
472 3697448 200 0 1436855699443390 1436855704443390 1436855699441708
1436855699443390 1 0
## Make request when the users sends a "If-Modified-Since" header. Client
(curl) has a stale copy, but the more recient version of the mod_cache can
be revalidated.
# curl --verbose '
http://localhost/Python/web/wms?request=GetCapabilities&service=WMS&version=1.3.0'
-H 'If-Modified-Since: Thu, 09 Jul 2015 20:26:45 GMT' > out
* Connected to localhost (::1) port 80 (#0)
> GET /Python/web/wms?request=GetCapabilities&service=WMS&version=1.3.0
HTTP/1.1
> User-Agent: curl/7.38.0
> Host: localhost
> Accept: */*
> If-Modified-Since: Thu, 09 Jul 2015 20:26:45 GMT
>
< HTTP/1.1 200 OK
< Date: Tue, 14 Jul 2015 06:35:32 GMT
* Server Apache/2.4.10 (Ubuntu) is not blacklisted
< Server: Apache/2.4.10 (Ubuntu)
< Last-Modified: Mon, 13 Jul 2015 07:33:49 GMT
< Vary: Accept-Encoding
< X-Cache: MISS from 172.17.1.37
< X-Cache-Detail: "cache miss: attempting entity save" from 172.17.1.37
< Transfer-Encoding: chunked
< Content-Type: text/xml
## Unfortunatetly, a cache miss.
root@1ce49e006c40:/var/oceanbrowser# cat
/etc/apache2/mods-enabled/cache_disk.conf
<IfModule mod_cache_disk.c>
# This path must be the same as the one in /etc/default/apache2
CacheRoot /var/cache/apache2/mod_cache_disk
# Enable the X-Cache header
CacheHeader on
# Enable the X-Cache-Detail header
CacheDetailHeader on
# The maximum size (in bytes) of a document to be placed in the cache
# GetCapabilities can be quite large, maximum here is 10 MB
CacheMaxFileSize 10000000
# The result of CacheDirLevels * CacheDirLength must not be higher than
# 20. Moreover, pay attention on file system limits. Some file systems
# do not support more than a certain number of inodes and
# subdirectories (e.g. 32000 for ext3)
CacheDirLevels 2
CacheDirLength 1
</IfModule>root@1ce49e006c40:/var/oceanbrowser# cat
/etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port
that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
# For debugging
LogLevel debug
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# Enable cache
<IfModule mod_cache.c>
CacheEnable disk /
</IfModule>
CustomLog ${APACHE_LOG_DIR}/cache-access.log common
CustomLog ${APACHE_LOG_DIR}/cache-cached-requests.log common
env=cache-hit
CustomLog ${APACHE_LOG_DIR}/cache-uncached-requests.log common
env=cache-miss
CustomLog ${APACHE_LOG_DIR}/cache-revalidated-requests.log common
env=cache-revalidate
CustomLog ${APACHE_LOG_DIR}/cache-invalidated-requests.log common
env=cache-invalidate
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
<Directory /var/oceanbrowser/apache>
Require all granted
</Directory>
WSGIDaemonProcess gher-diva.phys.ulg.ac.be processes=8 threads=15
WSGIProcessGroup gher-diva.phys.ulg.ac.be
WSGIScriptAlias / /var/oceanbrowser/apache/divaonweb.wsgi
WSGIApplicationGroup %{GLOBAL}
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
[users@httpd] Re: mod_cache issue if client send "If-Modified-Since" header.
Posted by Alexander Barth <ba...@gmail.com>.
Hi,
For your information, I tested the latest version of apache (from the ppa,
https://launchpad.net/~ondrej/+archive/ubuntu/apache2), and I have the same
behavior.
All the best,
Alex
Re: [users@httpd] mod_cache issue if client send "If-Modified-Since" header.
Posted by Alexander Barth <ba...@gmail.com>.
On Tue, Jul 14, 2015 at 12:32 PM, Nick Kew <ni...@webthing.com> wrote:
> On Tue, 2015-07-14 at 09:22 +0200, Alexander Barth wrote:
>
> > . The problem is that mod_cache ask to the python script if the
> > version from the 9 July can be revalidate (instead of its own more
> > recent version from the 13 July).
>
> You mean, mod_cache is passing the Client's header to the backend,
> when it could and should substitute its own?
Yes, this is exactly the problem. I checked that backend receives indeed
the client header.
> Or am I misreading you?
>
> Your report is rather long and detailed to review in email on
> this list. Is there anything about this in Bugzilla? If not,
> you could perhaps consider submitting a report.
>
I did not find this issue in Bugzilla. I created a new bug report here:
https://bz.apache.org/bugzilla/show_bug.cgi?id=58135
Thanks!
Alex
>
> --
> Nick Kew
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>
Re: [users@httpd] mod_cache issue if client send
"If-Modified-Since" header.
Posted by Nick Kew <ni...@webthing.com>.
On Tue, 2015-07-14 at 09:22 +0200, Alexander Barth wrote:
> . The problem is that mod_cache ask to the python script if the
> version from the 9 July can be revalidate (instead of its own more
> recent version from the 13 July).
You mean, mod_cache is passing the Client's header to the backend,
when it could and should substitute its own? Or am I misreading you?
Your report is rather long and detailed to review in email on
this list. Is there anything about this in Bugzilla? If not,
you could perhaps consider submitting a report.
--
Nick Kew
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org