Some understanding and suggestions on refresh_pattern in squid

Source: Internet
Author: User
Used to determine the time when a page enters the cache. The refresh_pattern rule applies only to responses with no definite expiration time. The original server can use the Expires header or the Cache-Control: max-age command to specify the Expiration Time. Squid

Refresh_pattern:
Used to determine the time when a page enters the cache. The refresh_pattern rule applies only to responses with no definite expiration time. The original server can use the Expires header or the Cache-Control: max-age command to specify the Expiration Time.
Syntax: refresh_pattern [-I] regexp min percent max [options]
The min parameter indicates the number of minutes. It is the minimum time limit for outdated responses. If the time for a response to reside in the cache does not exceed this minimum limit, it will not expire. Similarly, the max parameter is the maximum time limit for response survival. If the time for a response to reside in the cache exceeds this limit, it must be refreshed.
The response between the minimum and maximum time limits faces the LM-factor algorithm LM-factor = (response age)/(resource age) of squid ). For such a response, squid calculates the response age and the last modified coefficient, and then compares it as a percentage value. The response age is simply the amount of time that has elapsed since the origin server or after the last verification response. The source age is different between the Last-Modified and Date headers. LM-factor is the ratio of response age to source age.
Meanings of common parameters

Override-expire
This option causes squid to check the min value before checking the Expires header. In this way, a non-zero min time enables squid to return an unconfirmed cache hit even if the response preparation expires.

Override-lastmod
This option causes squid to check the min value before LM-factor percentage.

Reload-into-ims
This option allows squid to send a request using the no-cache command in the confirmation request. In other words, before forwarding a request, squid adds an If-Modified-Since header to the request. Note that this only works when the target has a Last-Modified timestamp. The incoming requests retain the no-cache command so that it can reach the original server.
Generally, reload-into-ims can be used. In fact, it is forced to control the object timeout time, which violates the spirit of the http protocol, but in the case of narrow bandwidth, it can significantly increase 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% reload-into-ims
Refresh_pattern-I \. hml $1440 90% 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 commands in the request.
So. If you want the content to enter the cache, it will not be deleted until it is actively purged. you can add the ignore-reload option, which is commonly used in mp3, wma, wmv, gif, and so on.
Examples:
Refresh_pattern-I \. mp3 $1440 50% 2880 ignore-reload
Refresh_pattern-I \. wmv $1440 50% 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% ignore-reload
Resource age = time when the object enters the cache-last_modified of the object
Response age = current time-time when the object enters the cache
LM-factor = (response age)/(resource age)
For example, here we only consider percent, not min and max.
For example, refresh_pattern 20%
Assume that www.aaa.com/index.htm ----- lastmodified on the source server is 02:00:00
The time when proxy.aaa.com/index.htm index.htm enters the cache on squid is 03:00:00

1) if the current time is 03:00:00
Resource age = 3-2 = 60 minutes
Response age = 0 minutes
Index.htm can also stay in the cache (resource age) * 20% = 12 minutes
In other words, after index.htm enters the cache, it can be reconfirmed after 12 minutes.

2) if the current time is 03:05:00
Resource age = 3-2 = 60 minutes
Response age = 5 minutes
Index.htm can also stay in the cache (resource age) * 20% = 12 minutes-5 = 7
LM-factor = 5/60 = 8.3% <20%

Until 03:12:00 LM-factor = 12/60 = 20%, the page index.htm in cacheis finally stale.
If there is no request for index.htmat this time, index.htmwill be saved slowly. if there is a request for index.htm, after squid receives the request, it does not need to update the cache because it has expired and the token has not been updated. it directly puts the cached content back to, the time when the reset object enters the cache is confirmed with the source server, for example, 03:13:00. if this happens, the page is re-confirmed. After resetting, the resource age becomes longer, and the time for survival in the cache also becomes longer.

If there is a change, the latest index.htmwill be returned to squid, and the new index.htm will be updated and saved. then, the new index.htm will be returned to the client, and the resource age will be re-calculated based on Last_Modified in the new page and.

In fact, after a page enters the cache, its survival time is determined, that is, (resource age) * percentage until it is re-confirmed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.