Some understandings and suggestions on refresh_pattern in squid _php skills

Source: Internet
Author: User
Tags min
the role of Refresh_pattern:
Used to determine the time that a page stays in the cache after it has entered the cache. The Refresh_pattern rule applies only to responses that do not have a clear outdated deadline. The original server can use the Expires header, or the cache-control:max-age instruction to specify the obsolete term.
Syntax: Refresh_pattern [i] regexp min percent max [options]
The min parameter is the number of minutes. It is the minimum time limit for outdated responses. If a response resides in the cache for no more than this minimum limit, it will not expire. Similarly, the max parameter is the maximum time limit for the surviving response. If a response resides in the cache for more time than this maximum limit, then it must be refreshed.
The response between the minimum and maximum time limits will face Squid's final modification coefficients lm-factor algorithm lm-factor= (response age)/(Resource). For such a response, Squid calculates the age of the response and the final modification factor, and then compares it as a percentage value. The response age is simply the amount of time that has been experienced since the original server was generated, or after the last validation response. The source age is different between the last-modified and the date head. Lm-factor is the ratio of the response age to the source age.
The meaning of several commonly used parameters

Override-expire
This option causes Squid to check the Min value before checking the expires head. In this way, a Non-zero min time lets squid return an unconfirmed cache hit, even if the response is ready to expire.

Override-lastmod
The re-election causes Squid to check the Min value before checking the lm-factor percentage.

Reload-into-ims
This option lets squid send a request with the no-cache instruction in the confirmation request. In other words, Squid adds a if-modified-since header to the request before forwarding the request. Note that this only works when the target has a last-modified time stamp. The incoming request retains the no-cache instruction so that it reaches the original server.
Reload-into-ims can be used in general. It is actually a force to control the object timeout, which violates the spirit of the HTTP protocol, but in the case of narrow bandwidth, you can improve the apparent system corresponding 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 instructions in the request.
So. If you want content to enter the cache will not be deleted, until the active purge off, you can add ignore-reload options, this we often 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% 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 = Object Entering cache time-Last_modified of object
Response Age = Current Time-When an object enters cache
Lm-factor= (response Age)/(Resource age)
For example, consider only percent, not min and Max.
For example: Refresh_pattern 20%
Suppose the source server www.aaa.com/index.htm-----lastmodified is 2007-04-10 02:00:00
Squid on proxy.aaa.com/index.htm index.htm Enter cache time 2007-04-10 03:00:00

1) If the current time 2007-04-10 03:00:00
Resource age = 3 point-2 point = 60 min
Response age = 0 minutes
Index.htm can also stay in cache (Resource age) *20%=12 minutes
In other words, index.htm into the cache, you can stay for 12 minutes before being reconfirmed.

2) If the current time 2007-04-10 03:05:00
Resource age = 3 point-2 point = 60 min
Response age = 5 minutes
Index.htm can also *20%=12 minutes on cache stay (resource age) -5=7
lm-factor=5/60=8.3%<20%

Until the 2007-04-10 03:12:00 lm-factor=12/60=20%, the cache in the page index.htm finally stale.
If there is no index.htm request, index.htm will always be in the cache, if there is a index.htm request, Squid received the request, because it has expired, Squid will send a index.htm to the source server whether there is a change in the request, the source server received, if the index.htm did not update, squid does not need to update the cache, directly put the cached content back to the client, while resetting the object into the cache time for the source server to confirm the time, such as 2007-0 4-10 03:13:00, if the page is reconfirmed after this. After resetting, the resource age becomes longer, and the corresponding time to survive in the cache becomes longer.

If there is a change, the newest index.htm is returned to the Squid,squid. The cache is updated, then the new index.htm is returned to the client, and the resource age is recalculated based on the last_modified and page-taking time in the new page. Further calculate the survival time.

In fact, when a page enters the cache, his survival time is determined, i.e. (resource age) * percent, until it is reconfirmed.

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.