I am using squid as proxy. But when the website is down and the cache is exceed the max time config in squid.conf, can I just let squid send the old to client before squid revaliadate it. If squid can do this, how to config?
2 Answers
You can use several options - refresh_pattern, max_stale, refresh_stale_hit, icp_hit_stale
If You dont need to serve stale content long time, then you can use only refresh_stale_hit option. i.e.:
refresh_stale_hit 1 minute
This allows concurrent requests while object is being refreshed to be processed as cache hits only if object expired less than 1 minute.
squid 2.7 or > 3.3 will use cache-control header stale-while-revalidate and stale-if-error
header('Cache-Control: public, max-age=0, s-maxage=60, stale-while-revalidate=120, stale-if-error=600');
would mean:
browser don't cache (to avoid double cache that can drive to strange things)
squid cache for 60s
for the next 120s deliver stale content and update cache (will mask latency of refreshing cache content)
and deliver stale content for 10min if server returns error.