Setup
$ squid -v
Squid Cache: Version 3.5.20
Service Name: squid
configure options: '--build=x86_64-koji-linux-gnu' '--host=x86_64-koji-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--disable-strict-error-checking' '--exec_prefix=/usr' '--libexecdir=/usr/lib64/squid' '--localstatedir=/var' '--datadir=/usr/share/squid' '--sysconfdir=/etc/squid' '--with-logdir=$(localstatedir)/log/squid' '--with-pidfile=$(localstatedir)/run/squid.pid' '--disable-dependency-tracking' '--enable-eui' '--enable-follow-x-forwarded-for' '--enable-auth' '--enable-auth-basic=DB,LDAP,MSNT-multi-domain,NCSA,NIS,PAM,POP3,RADIUS,SASL,SMB,SMB_LM,getpwnam' '--enable-auth-ntlm=smb_lm,fake' '--enable-auth-digest=file,LDAP,eDirectory' '--enable-auth-negotiate=kerberos' '--enable-external-acl-helpers=file_userip,LDAP_group,time_quota,session,unix_group,wbinfo_group,kerberos_ldap_group' '--enable-cache-digests' '--enable-cachemgr-hostname=localhost' '--enable-delay-pools' '--enable-epoll' '--enable-ident-lookups' '--enable-linux-netfilter' '--enable-removal-policies=heap,lru' '--enable-snmp' '--enable-ssl-crtd' '--enable-storeio=aufs,diskd,rock,ufs' '--enable-wccpv2' '--enable-esi' '--enable-ecap' '--with-aio' '--with-default-user=squid' '--with-dl' '--with-openssl' '--with-pthreads' '--disable-arch-native' 'build_alias=x86_64-koji-linux-gnu' 'host_alias=x86_64-koji-linux-gnu' 'CFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fpie' 'LDFLAGS=-Wl,-z,relro -pie -Wl,-z,relro -Wl,-z,now' 'CXXFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fpie' 'PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig'
$ cat /etc/squid.conf
cache_dir aufs /var/cache/squid/data 1024 16 256
http_access allow all
http_port 3128
negative_ttl 10 minutes
refresh_pattern . 1449 0% 11520
visible_hostname example
Positive responses
After the first request, positive responses are cached
$ http_proxy=http://localhost:3128 curl -I http://www.china.org.cn/
HTTP/1.1 200 OK
Content-Type: text/html
Date: Mon, 10 Jun 2019 00:37:28 GMT
Powered-By-ChinaCache: HIT from CNC-HQ-b-3g8
ETag: "928a-5cfda467"
Expires: Mon, 10 Jun 2019 00:40:00 GMT
Content-Length: 37514
Server: Sun-ONE-Web-Server/6.1
Accept-Ranges: bytes
CACHE: TCP_HIT
Powered-By-ChinaCache: HIT from USA-LA-5-D06
CC_CACHE: TCP_HIT
Accept-Ranges: bytes
Age: 39
X-Cache: HIT from example
X-Cache-Lookup: HIT from example:3128
Via: 1.1 example (squid/3.5.20)
Connection: keep-alive
1560127376.780 0 127.0.0.1 TCP_MEM_HIT/200 511 HEAD http://www.china.org.cn/ - HIER_NONE/- text/html```
Negative responses
After the first request, negative responses are not cached:
$ http_proxy=http://localhost:3128 curl -I http://www.china.org.cn/boaty-mcboatface
HTTP/1.1 404 Not Found
Content-Type: text/html
Content-Length: 292
Powered-By-ChinaCache: MISS from CNC-HQ-b-3g8
Date: Mon, 10 Jun 2019 00:34:32 GMT
Server: Sun-ONE-Web-Server/6.1
Powered-By-ChinaCache: MISS from USA-LA-5-D06
X-Cache: MISS from example
X-Cache-Lookup: MISS from example:3128
Via: 1.1 example (squid/3.5.20)
Connection: keep-alive
1560127438.188 2395 127.0.0.1 TCP_MISS/404 360 HEAD http://www.china.org.cn/boaty-mcboatface - HIER_DIRECT/106.48.13.98 text/html
and the response time is several hundred ms, consistent with a cache miss:
Why isn't Squid caching this negative response, and what can I do to get to cache it?