ãã©ã¦ã¶ãã£ãã·ã¥ã®æåãè¦ã¦ã¿ã
æ¹ãã¦åå¼·ãããã£ãã®ã§ããããªãã¹ããã¦ã¿ã¾ããã
Apacheã®è¨å®ã¨ãã¹ãå 容
<VirtualHost *:80> ServerAdmin zigorou@localhost DocumentRoot /home/zigorou/www/cache ServerName cachetest.art-code.org ExpiresDefault "access plus 5 minutes" Alias /test1 /home/zigorou/www/cache/test Alias /test2 /home/zigorou/www/cache/test Alias /test3 /home/zigorou/www/cache/test <Location /test1> FileETag None ExpiresActive Off </Location> <Location /test2> FileETag Size ExpiresActive Off </Location> <Location /test3> FileETag Size ExpiresActive On </Location> </VirtualHost>
ã©ãããè¨å®ãã¾ã¨ããã¨ã
test no | FileETag | ExpiresActive |
---|---|---|
1 | None | Off |
2 | Size | Off |
3 | Size | On |
ã£ã¦ãªã£ã¦ã¦ãããããã®ãã¹ã«å¯¾ãã¦If-Modified-Since, If-None-Match, Cache-Controlããããé£ã°ããªãã200 or 304ãªã®ãã©ãã調ã¹ã¦ã¿ãã
ãã¹ãã¹ã¯ãªãã
æè¿ã®ã¨ã³ããªã¯ããã«ç¹ãã£ã¦ã次第ã§ããï½
#!/usr/bin/perl use strict; use warnings; use Data::Dump qw(dump); use DateTime; use DateTime::Format::HTTP; use HTTP::Request; use LWP::UserAgent; use Set::CrossProduct; use Text::SimpleTable; my $date = DateTime::Format::HTTP->format_datetime(DateTime->now - DateTime::Duration->new(minutes => 30)); my $entries = { 'Cache-Control' => [q|no-cache|, q|max-age=0|, undef], 'If-None-Match' => [q|"2232"|, q|"2222"|, undef], 'If-Modified-Since' => [$date, undef] }; sub request { my ($url, $headers) = @_; my $ua = LWP::UserAgent->new; my $req = HTTP::Request->new('GET', $url); for (keys %$headers) { $req->header($_, $headers->{$_}) if ($headers->{$_}); } my $res = $ua->request($req); return ($req, $res); } my $cp = Set::CrossProduct->new([values %$entries]); my @headers = (); for my $header_vals ($cp->combinations) { my %header; @header{keys %$entries} = @$header_vals; push(@headers, \%header); } for my $idx (1..3) { my $table = Text::SimpleTable->new([6, "no"], [20, "Cache-Control"], [20, "If-None-Match"], [20, "If-Modified-Since"], [7, "status"]); my $url = sprintf("http://cachetest.art-code.org/test%d/logo.gif", $idx); my $hidx = 0; for my $header (@headers) { my ($req, $res) = request($url, $header); $table->row(++$hidx, values %$header, $res->code); } print "test$idx results: \n"; print $table->draw; }
ã¡ãªã¿ã«æ£ããETagã¯2232ã§ãã
ãã¨ãå®é¨ã§ã¢ã¯ã»ã¹ãã¦ããã¡ã¤ã«ã®statã¯ã
$ stat test/logo.gif File: `test/logo.gif' Size: 8754 Blocks: 12 IO Block: 1024 ã»evice: 3cb4a463h/1018471523d Inode: 844424930313348 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1006/zigorou) Gid: ( 513/ zigorou) Access: 2007-08-13 20:14:28.437500000 +0900 Modify: 2007-08-13 20:14:28.437500000 +0900 Change: 2007-08-13 20:14:28.437500000 +0900
ã§æ¨æ¥ãLast-Modifiedã«ãªã£ã¦ã¾ãã
å®é¨çµæ
FileETag: None, ExpiresActive Offã®å ´å
ã¾ãã¯çµæã
test1 results: .--------+----------------------+----------------------+----------------------+---------. | no | Cache-Control | If-None-Match | If-Modified-Since | status | +--------+----------------------+----------------------+----------------------+---------+ | 1 | no-cache | "2232" | Tue, 14 Aug 2007 07- | 200 | | | | | :59:19 GMT | | | 2 | no-cache | "2222" | Tue, 14 Aug 2007 07- | 200 | | | | | :59:19 GMT | | | 3 | no-cache | | Tue, 14 Aug 2007 07- | 304 | | | | | :59:19 GMT | | | 4 | no-cache | "2232" | | 200 | | 5 | no-cache | "2222" | | 200 | | 6 | no-cache | | | 200 | | 7 | max-age=0 | "2232" | Tue, 14 Aug 2007 07- | 200 | | | | | :59:19 GMT | | | 8 | max-age=0 | "2222" | Tue, 14 Aug 2007 07- | 200 | | | | | :59:19 GMT | | | 9 | max-age=0 | | Tue, 14 Aug 2007 07- | 304 | | | | | :59:19 GMT | | | 10 | max-age=0 | "2232" | | 200 | | 11 | max-age=0 | "2222" | | 200 | | 12 | max-age=0 | | | 200 | | 13 | | "2232" | Tue, 14 Aug 2007 07- | 200 | | | | | :59:19 GMT | | | 14 | | "2222" | Tue, 14 Aug 2007 07- | 200 | | | | | :59:19 GMT | | | 15 | | | Tue, 14 Aug 2007 07- | 304 | | | | | :59:19 GMT | | | 16 | | "2232" | | 200 | | 17 | | "2222" | | 200 | | 18 | | | | 200 | '--------+----------------------+----------------------+----------------------+---------'
ããããåããã®ã¯If-None-Matchããããéãã¨ãæç¡ãè¨ããããã£ãã·ã¥ãç¡å¹ã«ãªããæ°ããã³ã³ãã³ããWebãµã¼ãã¼ãè¿ãã£ã¦äºã
Cache-Controlã®no-cache, max-age=0ã¨ãã¯å ¨ç¶ç¡é¢ä¿ã
ãªã®ã§ãã®ç¶æ ã§æå¹ãªãããã¯If-Modified-Since, If-None-Matchã§ãIf-None-Matchã¯ãã£ãã·ã¥ç¡å¹ã«ç¡æ¡ä»¶ã«ãªããç¡ãã£ãã¨ãã«Last-Modifiedã¨If-Modified-Sinceã®æ¯è¼ãè¡ããã¦ãLast-Modified以éã®æ¥æãIf-Modified-Sinceã§éã£ã¦ããã°304ãè¿ã£ã¦æ¥ãã
FileETag: Size, ExpiresActive Offã®å ´å
çµæã¯ãã¡ãã
test2 results: .--------+----------------------+----------------------+----------------------+---------. | no | Cache-Control | If-None-Match | If-Modified-Since | status | +--------+----------------------+----------------------+----------------------+---------+ | 1 | no-cache | "2232" | Tue, 14 Aug 2007 07- | 304 | | | | | :59:19 GMT | | | 2 | no-cache | "2222" | Tue, 14 Aug 2007 07- | 200 | | | | | :59:19 GMT | | | 3 | no-cache | | Tue, 14 Aug 2007 07- | 304 | | | | | :59:19 GMT | | | 4 | no-cache | "2232" | | 304 | | 5 | no-cache | "2222" | | 200 | | 6 | no-cache | | | 200 | | 7 | max-age=0 | "2232" | Tue, 14 Aug 2007 07- | 304 | | | | | :59:19 GMT | | | 8 | max-age=0 | "2222" | Tue, 14 Aug 2007 07- | 200 | | | | | :59:19 GMT | | | 9 | max-age=0 | | Tue, 14 Aug 2007 07- | 304 | | | | | :59:19 GMT | | | 10 | max-age=0 | "2232" | | 304 | | 11 | max-age=0 | "2222" | | 200 | | 12 | max-age=0 | | | 200 | | 13 | | "2232" | Tue, 14 Aug 2007 07- | 304 | | | | | :59:19 GMT | | | 14 | | "2222" | Tue, 14 Aug 2007 07- | 200 | | | | | :59:19 GMT | | | 15 | | | Tue, 14 Aug 2007 07- | 304 | | | | | :59:19 GMT | | | 16 | | "2232" | | 304 | | 17 | | "2222" | | 200 | | 18 | | | | 200 | '--------+----------------------+----------------------+----------------------+---------'
æ£ããETagãéã£ã¦ãã°ã304ãè¿ã£ã¦æ¥ããéã«ETagã誤ã£ã¦ããã¨ç¡æ¡ä»¶ã«æ°ããã³ã³ãã³ããåããªãã¦ã¯ãªããªãã
ãã¨ã¯test1ã¨åçã
ãã¯ãCache-Controlã¯ç¡é¢ä¿ã£ã½ãã
FileETag: Size, ExpiresActive Onã®å ´å
çµæã¯test2ã¨åãã
test3 results: .--------+----------------------+----------------------+----------------------+---------. | no | Cache-Control | If-None-Match | If-Modified-Since | status | +--------+----------------------+----------------------+----------------------+---------+ | 1 | no-cache | "2232" | Tue, 14 Aug 2007 07- | 304 | | | | | :59:19 GMT | | | 2 | no-cache | "2222" | Tue, 14 Aug 2007 07- | 200 | | | | | :59:19 GMT | | | 3 | no-cache | | Tue, 14 Aug 2007 07- | 304 | | | | | :59:19 GMT | | | 4 | no-cache | "2232" | | 304 | | 5 | no-cache | "2222" | | 200 | | 6 | no-cache | | | 200 | | 7 | max-age=0 | "2232" | Tue, 14 Aug 2007 07- | 304 | | | | | :59:19 GMT | | | 8 | max-age=0 | "2222" | Tue, 14 Aug 2007 07- | 200 | | | | | :59:19 GMT | | | 9 | max-age=0 | | Tue, 14 Aug 2007 07- | 304 | | | | | :59:19 GMT | | | 10 | max-age=0 | "2232" | | 304 | | 11 | max-age=0 | "2222" | | 200 | | 12 | max-age=0 | | | 200 | | 13 | | "2232" | Tue, 14 Aug 2007 07- | 304 | | | | | :59:19 GMT | | | 14 | | "2222" | Tue, 14 Aug 2007 07- | 200 | | | | | :59:19 GMT | | | 15 | | | Tue, 14 Aug 2007 07- | 304 | | | | | :59:19 GMT | | | 16 | | "2232" | | 304 | | 17 | | "2222" | | 200 | | 18 | | | | 200 | '--------+----------------------+----------------------+----------------------+---------'
ä½ãéããã¨è¨ãã°ã
Cache-Control: max-age=300 Expires: Tue, 14 Aug 2007 08:43:02 GMT
ã®ããã«Cache-Control, Expiresããããã¬ã¹ãã³ã¹ãããã§è¿ãã£ã¦äºã
ããããã©ã¦ã¶ãåãåãé常ãæéãåãã¦å±
ãªãå ´åã¯ãªã¯ã¨ã¹ãèªä½é£ã°ããªãäºã«ãªãã
ãã¨ã奥ããã®ã¨ã³ããªãåæ§ã«è¦ãã¨åå¼·ã«ãªãã¾ãã