Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to judge whether a HTTP resource is cacheable or not through ATS cache configuration

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

A major principle of caching is to cache resources locally as much as possible without affecting users and breaking the law. Which HTTP resources can be cache and which cannot cache,ATS has a set of systematic judgment mechanism for cacheability, flexible setting, can be configured globally or individually, can be configured for a single url or file suffix type, normal resources can be configured or fault information (status code more than 400) can be configured. Static resources can be configured or dynamic resources can be configured separately, so take a look at it now.

1. HTTP response header information configuration cache level

Most resources in any cache system are cacheable by HTTP header information, and the same is true for ATS. The configuration of this header information is a necessary condition for whether a resource is cache or not, and resources are divided into three levels according to the header information, namely:

2. There is a clear cache life cycle, such as expires (when to expire) or Cache-Control: (max-age, no-cache) in the response header. This setting is the most responsible to users and will not make mistakes. This level is used by default in our online ATS.

1. If there is a Last-Modified header or a clear cache life cycle, this level will be loosened. Even if the resource does not have a clear cache cycle, the cache time can be calculated through the Last-Modified header combined with ATS's own algorithm mechanism (the concept of aging factor is introduced). Cache the resource, and see the fifth item below for how long.

0. On the basis of level 1, resources without clear header information are stored in the local cache by default. See the fifth section below for how long, and then if-modified-since origin each time.

The corresponding configurations are as follows:

Proxy.config.http.cache.required_headers 0 | 1 | 2 (0: no requirement, 1: Last-Modified header or clear cache lifecycle, 2: explicit cache lifecycle)

This is a necessary and insufficient condition for whether all ATS content is cacheable or not.

Second, whether the dynamic content is cached

ATS does not use rational judgment to determine whether resources are dynamic, as people do. His judgment of dynamic and static resources depends entirely on url feature matching. Our online default configuration is not cached, and the corresponding configuration parameters are:

Proxy.config.http.cache.cache_urls_that_look_dynamic 0 | 1 (0 is not cached, 1 is cacheable)

This is a necessary and insufficient condition for whether dynamic content ATS can be cached or not.

3. Whether resources with cookie are cached

In web2.0 's website, many resources have cookie. Whether the information of cookie is cached and how to cache it without affecting the quality of users tests the performance of cache system. ATS's settings for cookie are divided into five levels:

Proxy.config.http.cache.cache_responses_to_cookies INT 0 | 1 | 2 | 3 | 4

0. Any resources with cookie are not cached

1. Any resource with cookie is cached

2. Only cache cookie resources that are images

3. All cookie resources are cached except for the text type.

4. All cookie resources are cached except that there is no "Set-Cookie" or text type with "Cache-Control:public" that the system responds to. (the default configuration level of our online devices)

This is a necessary and insufficient condition for whether the cookie content ATS is cacheable.

Fourth, whether the fault information is cached

The so-called fault information refers to the error codes such as 4XX and 5XX returned by the origin server. Whether the fault information is cached or not is controversial. ATS divides the fault information into two categories: one is a fault with a clear life cycle, and the other is a fault without a life cycle. The configuration parameters are as follows:

Proxy.config.http.negative_caching_enabled 0 | 1 (1 caches all fault information. 0 means only caching fault information with a clear life cycle. 0 is used online by default)

Proxy.config.http.negative_caching_lifetime 2s (the cache time for failure information with a clear cache life cycle can be set according to the time time. Currently, the default is 2s online)

Information resources that do not have any cache description in the request header and response header

Ats for this kind of information is controlled by the proxy.config.http.cache.required_headers header plus the default time instruction. For example, the header header is set to level 0, which means the loosest policy is set for the header information. In this case, a request, if there are no Cache-control, expires, Last-Modified fields, but has a Last-Modified header, the cache time is calculated by minimizing the factor. The corresponding instruction and calculation method are as follows:

Proxy.config.http.cache.heuristic_lm_factor FLOAT 0.100000 (cache time = current time minus Last-Modified time * 0.1)

The default storage time is used to calculate the information that does not have a Last-Modified header. The judgment logic of this nginx is similar, but the nginx determines whether it is cached or not before operating. However, whether the ats is saved or not is separated from how long it will be stored, even if the storage time is 0. These two instructions are as follows:

Proxy.config.http.cache.heuristic_min_lifetime INT 3600

Proxy.config.http.cache.heuristic_max_lifetime INT 17280000

The unit is seconds, that is, a minimum of 3600 seconds and a maximum of 17280000 seconds for this kind of resource without any cache information.

In fact, none of these three instructions are needed for online environments, because we set the level of the header header to 2.

To sum up: for ats, the storage setting is very flexible and can be set separately for all kinds of resources. if it is not enough, you can set a single resource in cache.config (influence cache-control field). Of course, every link is logical. Let me give you an example. Now, for example, I want to cache all resources except authorization types forcibly for 10 days, and do not pull back to the origin during the cache period. This can be set as follows:

Traffic_line-s proxy.config.http.cache.cache_urls_that_look_dynamic-v 1

Traffic_line-s proxy.config.http.cache.cache_responses_to_cookies-v 1

Traffic_line-s proxy.config.http.cache.required_headers-v 0

Traffic_line-s proxy.config.http.cache.heuristic_min_lifetime-v 8640000

Traffic_line-s proxy.config.http.cache.heuristic_max_lifetime-v 8640000

Traffic_line-s proxy.config.http.cache.heuristic_lm_factor-v 0.5

Traffic_line-s proxy.config.http.cache.when_to_revalidate-v 3

Cache.config url_regex=.* scheme=http ttl-in-cache=240h

Build your own original station, Operation and maintenance Network (www.net-add.com). The new blog will be updated at the personal station. Welcome to visit.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report