Home >Backend Development >PHP Tutorial >urlpattern Some understanding and suggestions on refresh_pattern in Squid
The role of refresh_pattern:
The above introduces some understanding and suggestions of urlpattern on refresh_pattern in Squid, including the content of urlpattern. I hope it will be helpful to friends who are interested in PHP tutorials.
is used to determine how long a page stays in the cache after it enters the cache. The refresh_pattern rule only applies to responses that do not have an explicit expiration date. The origin server can specify the expiration period using the Expires header, or the Cache-Control:max-age directive.
Syntax: refresh_pattern [-i] regexp min percent max [options]
The min parameter is the number of minutes. It is the minimum time limit for stale responses. If a response does not reside in the cache longer than this minimum limit, it will not expire. Similarly, the max parameter is the maximum time limit for a live response. If a response resides in the cache longer than this maximum limit, it must be flushed.
Responses between the minimum and maximum time limits will face Squid's last modified coefficient LM-factor algorithm LM-factor=(response age)/(resource age). For such a response, Squid calculates the age and last modification coefficient of the response and compares it as a percentage value. Response age is simply the amount of time that has elapsed since the original server generated or last validated the response. The source age is different between Last-Modified and Date headers. LM-factor is the ratio of response age to source age.
The meaning of several commonly used parameters
override-expire
This option causes Squid to check the min value before checking the Expires header. Thus, a non-zero min time allows Squid to return an unacknowledged cache hit, even if the response is ready to expire.
override-lastmod
Change the option to cause Squid to check the min value before checking the LM-factor percentage.
reload-into-ims
This option allows Squid to send a request with the no-cache directive in the confirmation request. In other words, Squid adds an If-Modified-Since header to the request before forwarding it. Note that this only works if the target has a Last-Modified timestamp. Incoming requests from the outside retain the no-cache directive so that it reaches the origin server.
In general, reload-into-ims can be used. It actually forcibly controls the timeout of the object, which violates the spirit of the http protocol. However, in situations with narrow bandwidth, it can significantly improve the system response time.
Example:
refresh_pattern -i .css$ 1440 50% 129600 reload-into-ims
refresh_pattern -i .xml$ 1440 50% 129600 reload-into-ims
refresh_pattern -i .html$ 1440 90% 129 600 reload-into -ims-
refresh_pattern -i .shtml$ 1440 90% 129600 reload-into-ims
refresh_pattern -i .hml$ 1440 90% 129600 reload-into-ims
refresh_pattern -i .jpg$ 1440 90% 129600 reload- into- ims
refresh_pattern -i .png$ 1440 90% 129600 reload-into-ims
refresh_pattern -i .gif$ 1440 90% 129600 ignore-reload
refresh_pattern -i .bmp$ 1440 90% 129600 reload-into-ims
refresh_pattern - i .js$ 1440 90% 129600 reload-into-ims
ignore-reload
This option causes Squid to ignore any no-cache directives in the request.
So. If you want the content not to be deleted once it enters the cache until it is actively purged, you can add the ignore-reload option. This is commonly used in mp3, wma, wmv, gif, etc.
Examples:
refresh_pattern -i .mp3$ 1440 50% 2880 ignore-reload
refresh_pattern -i .wmv$ 1440 50% 2880 ignore-reload
refresh_pattern -i .rm$ 1440 50% 2880 ignore-reload
refresh_pat tern -i . swf$ 1440 50% 2880 ignore-reload
refresh_pattern -i .mpeg$ 1440 50% 2880 ignore-reload
refresh_pattern -i .wma$ 1440 50% 2880 ignore-reload
resource age = the time the object entered the cache - the last_modified of the object
response age = current time - the time when the object entered the cache
LM-factor = (response age)/(resource age)
For example, only percent is considered here, min and max are not considered
For example: refresh_pattern 20%
Assuming source www.aaa.com/index.htm on the server -----lastmodified is 2007-04-10 02:00:00
proxy.aaa.com/index.htm on Squid The time index.htm entered the cache is 2007-04 -10 03:00:00
1) If the current time is 2007-04-10 03:00:00
resource age =3 o'clock-2 o'clock=60 minutes
response age =0 minutes
index.htm can also stay in the cache The time (resource age)*20%=12 minutes
In other words, after index.htm enters the cache, it can stay for 12 minutes before being reconfirmed.
2) If the current time is 2007-04-10 03:05:00
resource age =3 o'clock-2 o'clock=60 minutes
response age =5 minutes
index.htm can still stay in the cache (resource age)* 20%=12 minutes-5=7
LM-factor=5/60=8.3%<20%
Until 2007-04-10 03:12:00 LM-factor=12/60=20%, after that, cache The page in index.htm is finally stale.
If there is no request for index.htm at this time, index.htm will always be in the cache. If there is a request for index.htm, after Squid receives the request, since it has expired, Squid will send a query to the source server to see if index.htm exists. After the source server receives the changed request, if index.htm has not been updated, Squid does not need to update the cache and directly returns the cached content to the client. At the same time, the time when the reset object enters the cache is the time confirmed with the source server. , such as 2007-04-10 03:13:00, if the page is reconfirmed just after this. After the reset, the resource age becomes longer, and the corresponding survival time in the cache also becomes longer.
If there is a change, return the latest index.htm to Squid. Squid will update the cache after receiving it, and then return the new index.htm to the client. At the same time, the resource will be recalculated based on the Last_Modified in the new page and the time when the page was fetched. age, further calculate the survival time.
In fact, after a page enters the cache, its survival time is determined, that is, (resource age) * percentage, until it is reconfirmed.