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

What is the purpose of Solr httpCache caching

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article introduces the knowledge of "what is the role of Solr httpCache cache". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Solr httpCache is mainly used to determine the two values of If-Modified-Since and If-None-Match of the request header header of the current search request request

The two header information of If-Modified-Since and If-None-Match can refer to my other article.

About Last-Modified and If-Modified-Since

For the httpCache cache of Solr to take effect, you need to modify the configuration file solrconfig.xml of solr, because the filter of solr makes the following judgment:

HttpCacheHeaderUtil.setCacheControlHeader (config, resp, reqMethod)

If (config.getHttpCachingConfig () .isNever304 () | |

! HttpCacheHeaderUtil.doCacheHeaderValidation (solrReq, req, reqMethod, resp) {

Here is all the work that needs to be done without httpcache caching.

}

To cache, first let solr generate header information, which is done in HttpCacheHeaderUtil.setCacheControlHeader

The code is as follows:

If (Method.POST==method | | Method.OTHER==method) {

Return

}

Final String cc = conf.getHttpCachingConfig () .getCacheControlHeader ()

If (null! = cc) {

Resp.setHeader ("Cache-Control", cc)

}

Long maxAge = conf.getHttpCachingConfig () .getMaxAge ()

If (null! = maxAge) {

Resp.setDateHeader ("Expires", System.currentTimeMillis ()

+ (maxAge * 1000L))

}

However, solr is not enabled by default. You need to change the solrconfig configuration file as follows:

Max-age=30, public

You can choose either of the two, and if you choose both, the first one is valid.

Just remove the comments from the httpcache. Solr takes the value of cacheControl when initializing it. The above code CC is the value of cacheControl.

As you can see from the above code, the value of max-age written to the Expires of header indicates the validity period of the resource (in seconds).

Public means all resources are available. If the value of cc is empty, SOlr does not generate header information, causing the relevant header information to be empty the next time the client requests.

The value of config.getHttpCachingConfig (). IsNever304 () is in the configuration file solrconfig.xml

The default value is true. As can be seen from the above if, if it is true, httpCache caching is not enabled.

So to enable httpcache caching, first change this value to false, which is changed here, and solr will determine whether to use httpcache directly based on the head header. This is judged and realized in HttpCacheHeaderUtil.doCacheHeaderValidation. The code is as follows:

If (Method.POST==reqMethod | | Method.OTHER==reqMethod) {

Return false

}

Final long lastMod = HttpCacheHeaderUtil.calcLastModified (solrReq)

Final String etag = HttpCacheHeaderUtil.calcEtag (solrReq)

Resp.setDateHeader ("Last-Modified", lastMod)

Resp.setHeader ("ETag", etag)

If (checkETagValidators (req, resp, reqMethod, etag)) {

Return true

}

If (checkLastModValidators (req, resp, lastMod)) {

Return true

}

As you can see from the above, if it is a post request, httpCache caching will not be enabled

The value of lastMod is the last modified time of the index, which is based on the

The value of lastModifiedFrom is calculated. When opentime, lastModifiedFrom is the opening time of solr index. If not, the default is also.

The value of etagSeed is used to calculate etag, generating a unique value based on the value of etag. And write to the client. "what is the role of Solr httpCache cache" is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Servers

Wechat

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

12
Report