Home  >  Article  >  Backend Development  >  Some understanding and suggestions on refresh_pattern in Squid_PHP Tutorial

Some understanding and suggestions on refresh_pattern in Squid_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:47:15856browse

The role of refresh_pattern:
is used to determine how long a page will stay 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 responses, Squid calculates the age and last modification coefficient of the response and compares it as a percentage value. The 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.
Generally, you can use reload-into-ims. 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% 129600 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_pattern -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 when the object entered the cache - the last_modified of the object
response age = the current time - the time when the object entered the cache
LM-factor=(response age)/(resource age)
As an example, only percent is considered here, min and max are not considered
For example: refresh_pattern 20%
Assume that www.aaa.com/index.htm -----lastmodified on the source server is 2007-04-10 02 :00:00
The time when proxy.aaa.com/index.htm index.htm on Squid entered the cache 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 still stay in the cache (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 also The time that can 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 After LM-factor=12/60=20%, the page index.htm in the cache finally becomes 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 an index.htm to the source server. If there is a changed request, after the source server receives it, 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 confirmed with the source server. time, such as 2007-04-10 03:13:00, if the page is reconfirmed exactly after this time.After the reset, the resource age becomes longer, and the corresponding survival time in the cache also becomes longer.

If there are changes, 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, according to the Last_Modified in the new page and the page's time, recalculate the resource age, and 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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320005.htmlTechArticleThe role of refresh_pattern: used to determine how long a page will stay in the cache after it enters the cache. The refresh_pattern rule only applies to responses that do not have an explicit expiration date. Original service...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn