jalankan command dibawah ini pada mesin Proxy :
curl -I http://192.168.7.2/squid.txt
Response Header
HTTP/1.1 200 OK
Cache-Control: max-age=300, public
Content-Type: text/plain
Accept-Ranges: bytes
ETag: “3497351881”
Last-Modified: Thu, 05 Sep 2013 08:10:44 GMT
Content-Length: 1354
Date: Mon, 16 Jun 2014 01:33:49 GMT
Server: WEB-SERVER-KU-SENDIRI
diskusi kali ini tentang
Cache-Control: max-age=300, public (CMIIW)
public
response cache-control “public” meng-informasikan bahwa objek
squid.txt ini boleh disimpan didalam cache
max-age
response cache-control “max-age=300” meng-informasikan bahwa umur objek
squid.txt
didalam “cache” tdk boleh lebih dari angka 300 detik atau 5 menit atau
dengan kata lain objek ini dianggap FRESH jika kurang dari 300 detik
didalam “cache”
max-age ini di set oleh Web Developer untuk mengontrol
“Freshness/kesegaran” dari objek tadi, Supaya user tidak menerima konten
yang basi/stale dari “cache”. Setelah umur objek didalam “cache”
melewati max-age, “cache” akan melakukan pengecekan ke Web Server asal
(validasi), apakah objek sudah berubah atau belum.
Sekarang kita lihat bagaimana SQUID bekerja, jika response max-age sudah lebih dari 300 detik
1. SQUID mendengar ada permintaan file
squid.txt
———-
2014/06/16 08:39:13.453 kid1|
client_side.cc(2407) parseHttpRequest: HTTP Client local=192.168.7.2:80 remote=192.168.6.2:1080 FD 24 flags=33
2014/06/16 08:39:13.453 kid1|
client_side.cc(2408) parseHttpRequest: HTTP Client REQUEST:
———
GET /
squid.txt HTTP/1.1
Host: 192.168.7.2
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:29.0) Gecko/20100101 Firefox/29.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
2. Karena file
squid.txt , sudah ada didalam “cache” maka dicek Freshness nya dengan directive refresh_pattern di file
squid.conf
———-
2014/06/16 08:39:13.453 kid1|
refresh.cc(247) refreshCheck: refreshCheck: ‘
http://192.168.7.2/squid.txt‘
2014/06/16 08:39:13.453 kid1|
refresh.cc(262) refreshCheck: refreshCheck: Matched
‘. 0 0%% 259200’
2014/06/16 08:39:13.453 kid1|
refresh.cc(264) refreshCheck:
age: 324
2014/06/16 08:39:13.454 kid1|
refresh.cc(266) refreshCheck: check_time: Mon, 16 Jun 2014 01:39:13 GMT
2014/06/16 08:39:13.454 kid1|
refresh.cc(268) refreshCheck: entry->timestamp: Mon, 16 Jun 2014 01:33:49 GMT
2014/06/16 08:39:13.454 kid1|
refresh.cc(176) refreshStaleness: STALE: expires 1402882729 < check_time 1402882753
2014/06/16 08:39:13.454 kid1|
refresh.cc(288) refreshCheck:
Staleness = 24
2014/06/16 08:39:13.458 kid1|
refresh.cc(540) getMaxAge: getMaxAge: ‘
http://192.168.7.2/squid.txt‘
2014/06/16 08:39:13.459 kid1|
http.cc(2219) sendRequest: HTTP Server local=192.168.5.2:52722 remote=192.168.7.2:80 FD 25 flags=1
2014/06/16 08:39:13.459 kid1|
http.cc(2220) sendRequest: HTTP Server REQUEST:
———
ternyata umur objek didalam “cache” sdh lebih dari 300 detik
age: 324
squid.txt ini dianggap stale/basi, harus dicek ulang ke Web Server asalnya 192.168.7.2
3. SQUID bilang ke Om Web Server
“Om Web Server minta file
squid.txt yang tanggal modifikasinya
Thu, 05 Sep 2013 08:10:44 GMT atau Etag nya bukan
“3497351881”
GET /
squid.txt HTTP/1.1
If-Modified-Since: Thu, 05 Sep 2013 08:10:44 GMT
If-None-Match: “3497351881”
Host: 192.168.7.2
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:29.0) Gecko/20100101 Firefox/29.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
X-Forwarded-For: 192.168.6.2
Cache-Control: max-age=259200
Connection: keep-alive
4. diresponse sama om Web Server
“Om SQUID,
squid.txt belum ada perubahan (304 Not Modified), tanggal modifikasi terakhir masih
Thu, 05 Sep 2013 08:10:44 GMT dan Etagnya jg msh sama
“3497351881”
———-
2014/06/16 08:39:13.465 kid1| ctx: enter level 0: ‘
http://192.168.7.2/squid.txt‘
2014/06/16 08:39:13.465 kid1|
http.cc(749) processReplyHeader: HTTP Server local=192.168.5.2:52722 remote=192.168.7.2:80 FD 25 flags=1
2014/06/16 08:39:13.465 kid1|
http.cc(750) processReplyHeader: HTTP Server REPLY:
———
HTTP/1.1 304 Not Modified
Cache-Control: max-age=300, public
Vary: Accept-Encoding
Content-Type: text/plain
Last-Modified: Thu, 05 Sep 2013 08:10:44 GMT
ETag: “3497351881”
Date: Mon, 16 Jun 2014 01:39:13 GMT
Server: WEB-SERVER-KU-SENDIRI
5. OK, kalo gitu gue kasi yg ada di “cache” aja karena masih sama
———-
2014/06/16 08:39:13.465 kid1| ctx: exit level 0
2014/06/16 08:39:13.465 kid1| ctx: enter level 0: ‘
http://192.168.7.2/squid.txt‘
2014/06/16 08:39:13.465 kid1|
http.cc(568) cacheableReply: NO because HTTP status 304
2014/06/16 08:39:13.466 kid1| ctx: exit level 0
2014/06/16 08:39:13.466 kid1|
client_side.cc(1459) sendStartOfMessage: HTTP Client local=192.168.7.2:80 remote=192.168.6.2:1080 FD 24 flags=33
2014/06/16 08:39:13.466 kid1|
client_side.cc(1460) sendStartOfMessage: HTTP Client REPLY:
———
HTTP/1.1 200 OK
Content-Encoding: gzip
Last-Modified: Thu, 05 Sep 2013 08:10:44 GMT
Content-Type: text/plain
Accept-Ranges: bytes
Content-Length: 1354
Cache-Control: max-age=300, public
Vary: Accept-Encoding
ETag: “3497351881”
Date: Mon, 16 Jun 2014 01:39:13 GMT
Server: WEB-SERVER-KU-SENDIRI
Age: 0
X-Cache: HIT from SQUIDLOVERS
Connection: keep-alive
di
access.log , akan terlihat :
1402882753.468 15 192.168.6.2 TCP_REFRESH_UNMODIFIED/200 1717 GET http://192.168.7.2/squid.txt – ORIGINAL_DST/192.168.7.2 text/plain
file
squid.txt masih diambil dari “cache” tapi dengan memvalidasi dulu ke Web Server asal makanya muncul
TCP_REFRESH_UNMODIFIED/200 dan
X-Cache: HIT from SQUIDLOVERS
Bagaimana response yang diterima jika ternyata file
squid.txt sudah ada perubahan ?
1. SQUID mendengar ada permintaan file
squid.txt
2014/06/16 14:55:51.722 kid1|
client_side.cc(2407) parseHttpRequest: HTTP Client local=192.168.7.2:80 remote=192.168.6.2:1184 FD 22 flags=33
2014/06/16 14:55:51.722 kid1|
client_side.cc(2408) parseHttpRequest: HTTP Client REQUEST:
———
GET /
squid.txt HTTP/1.1
Host: 192.168.7.2
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:29.0) Gecko/20100101 Firefox/29.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
2. Karena file
squid.txt , sudah ada didalam “cache” maka dicek Freshness nya dengan directive refresh_pattern di file
squid.conf
———-
2014/06/16 14:55:51.723 kid1|
refresh.cc(247) refreshCheck: refreshCheck: ‘
http://192.168.7.2/squid.txt‘
2014/06/16 14:55:51.723 kid1|
refresh.cc(262) refreshCheck: refreshCheck: Matched ‘
. 0 0%% 604800‘
2014/06/16 14:55:51.723 kid1|
refresh.cc(264) refreshCheck:
age: 5712
2014/06/16 14:55:51.723 kid1|
refresh.cc(266) refreshCheck: check_time: Mon, 16 Jun 2014 07:55:51 GMT
2014/06/16 14:55:51.723 kid1|
refresh.cc(268) refreshCheck: entry->timestamp: Mon, 16 Jun 2014 06:20:39 GMT
2014/06/16 14:55:51.723 kid1|
refresh.cc(176) refreshStaleness: STALE: expires 1402899939 < check_time 1402905351
2014/06/16 14:55:51.723 kid1|
refresh.cc(288) refreshCheck:
Staleness = 5412
2014/06/16 14:55:51.724 kid1|
refresh.cc(540) getMaxAge: getMaxAge: ‘
http://192.168.7.2/squid.txt‘
2014/06/16 14:55:51.724 kid1|
http.cc(2219) sendRequest: HTTP Server local=192.168.5.2:52789 remote=192.168.7.2:80 FD 23 flags=1
2014/06/16 14:55:51.724 kid1|
http.cc(2220) sendRequest: HTTP Server REQUEST:
———
ternyata umur objek didalam “cache” sdh lebih dari 300 detik
age: 5712
3. SQUID bilang ke Om Web Server
“Om Web Server minta file
squid.txt yang tanggal modifikasinya
Thu, 05 Sep 2013 08:10:44 GMT atau Etag nya bukan
“3497351881”
GET /
squid.txt HTTP/1.1
If-Modified-Since: Thu, 05 Sep 2013 08:10:44 GMT
If-None-Match: “3497351881”
Host: 192.168.7.2
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:29.0) Gecko/20100101 Firefox/29.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
X-Forwarded-For: 192.168.6.2
Cache-Control: max-age=604800
Connection: keep-alive
4. diresponse sama om Web Server
“Om SQUID, file
squid.txt sudah ada perubahan , tanggal modifikasi terakhir
Mon, 16 Jun 2014 07:52:29 GMT dan Etag
baru
“3148978175″
———-
2014/06/16 14:55:51.747 kid1| ctx: enter level 0: ‘
http://192.168.7.2/squid.txt‘
2014/06/16 14:55:51.747 kid1|
http.cc(749) processReplyHeader: HTTP Server local=192.168.5.2:52789 remote=192.168.7.2:80 FD 23 flags=1
2014/06/16 14:55:51.747 kid1|
http.cc(750) processReplyHeader: HTTP Server REPLY:
———
HTTP/1.1 200 OK
Cache-Control: max-age=300, public
Vary: Accept-Encoding
Content-Encoding: gzip
Last-Modified:
Mon, 16 Jun 2014 07:52:29 GMT
ETag:
“3148978175”
Content-Type: text/plain
Accept-Ranges: bytes
Content-Length: 1388
Date: Mon, 16 Jun 2014 07:55:52 GMT
Server: WEB-SERVER-KU-SENDIRI
5. OK, Om Web Server. Response baru saya simpan kedalam cache
2014/06/16 14:55:51.747 kid1| ctx: exit level 0
2014/06/16 14:55:51.747 kid1| ctx: enter level 0: ‘
http://192.168.7.2/squid.txt‘
2014/06/16 14:55:51.747 kid1|
refresh.cc(247) refreshCheck: refreshCheck: ‘
http://192.168.7.2/squid.txt‘
2014/06/16 14:55:51.747 kid1|
refresh.cc(262) refreshCheck: refreshCheck: Matched ‘. 0 0%% 604800’
2014/06/16 14:55:51.747 kid1|
refresh.cc(264) refreshCheck: age: 60
2014/06/16 14:55:51.747 kid1|
refresh.cc(266) refreshCheck: check_time: Mon, 16 Jun 2014 07:56:51 GMT
2014/06/16 14:55:51.747 kid1|
refresh.cc(268) refreshCheck: entry->timestamp: Mon, 16 Jun 2014 07:55:51 GMT
2014/06/16 14:55:51.747 kid1|
refresh.cc(171) refreshStaleness: FRESH: expires 1402905651 >= check_time 1402905411
2014/06/16 14:55:51.747 kid1|
refresh.cc(288) refreshCheck: Staleness = -1
2014/06/16 14:55:51.747 kid1|
refresh.cc(373) refreshCheck: refreshCheck: object isn’t stale..
2014/06/16 14:55:51.747 kid1|
refresh.cc(375) refreshCheck: refreshCheck: returning FRESH_EXPIRES
2014/06/16 14:55:51.747 kid1|
http.cc(482) cacheableReply: YES because HTTP status 200
2014/06/16 14:55:51.748 kid1| ctx: exit level 0
5. File
squid.txt yang baru dikasi ke klien
2014/06/16 14:55:51.748 kid1|
client_side.cc(1459) sendStartOfMessage: HTTP Client local=192.168.7.2:80 remote=192.168.6.2:1184 FD 22 flags=33
2014/06/16 14:55:51.748 kid1|
client_side.cc(1460) sendStartOfMessage: HTTP Client REPLY:
———
HTTP/1.1 200 OK
Cache-Control: max-age=300, public
Vary: Accept-Encoding
Content-Encoding: gzip
Last-Modified: Mon, 16 Jun 2014 07:52:29 GMT
ETag: “3148978175”
Content-Type: text/plain
Accept-Ranges: bytes
Content-Length: 1388
Date: Mon, 16 Jun 2014 07:55:52 GMT
Server: WEB-SERVER-KU-SENDIRI
X-Cache: MISS from SQUIDLOVERS
Connection: keep-alive
setelah di validasi ke Web Server asal ternyata file
squid.txt sudah mengalami perubahan, maka
di
access.log terlihat :
1402905351.749 26 192.168.6.2
TCP_REFRESH_MODIFIED/200 1744 GET
http://192.168.7.2/squid.txt – ORIGINAL_DST/192.168.7.2 text/plain
di
store.log terlihat
1402905351.748
SWAPOUT 00 0000119F 3C0D8CC25DB1A1A59C926301BA3B6319 200 1402905352 1402905149 1402905652 text/plain 1388/1388 GET
http://192.168.7.2/squid.txt
SWAPOUT berarti file
squid.txt yang baru disimpan ke dalam cache.
lalu bagaimana memaksa agar objek tersebut bisa lebih dari max-age -nya tp dianggap FRESH ?
mainkan refresh_pattern dengan opsi override-expire
opsi override-expire akan memaksa menggunakan angka min yang kita buat pada refresh_pattern di squid.conf meskipun Web Server memberikan cache-control max-age atau expire header
Format penulisan refresh_pattern
refresh_pattern [-i] regex min percent max [options]
contoh :
jadi yg perlu di set adalah nilai min saja, nilai max terserah
:-D, selamat menikmati HIT
WARNING :
Doing this VIOLATES the HTTP standard. Enabling this feature could make you liable for problems which it causes.