Solr 6.0 学习(十三)Solr缓存

Solr是基于Lucene的全文搜索服务器。实际上所有的搜索索引文件都是以文件形式存储在磁盘中。数据量到一定程度上,磁盘的IO会影响搜索性能。那么针对这种情况,我们优化的过程中势必需要运用缓存技术。目前,我们熟知的缓存nosql数据库:redis、mongodb、memcache。不过,本文不在这里针对这些nosql数据库做讨论,本文主要是针对solr已经实现的缓存技术做探讨。

1、httpcache

  • xml配置

    我们看到solrconfig.xml文件中的配置:

<httpCaching never304="true" />
    <!-- If you include a <cacheControl> directive, it will be used to
         generate a Cache-Control header (as well as an Expires header
         if the value contains "max-age=")

         By default, no Cache-Control header is generated.

         You can use the <cacheControl> option even if you have set
         never304="true"
      -->
    <!--
       <httpCaching never304="true" >
         <cacheControl>max-age=30, public</cacheControl> 
       </httpCaching>
      -->
    <!-- To enable Solr to respond with automatically generated HTTP
         Caching headers, and to response to Cache Validation requests
         correctly, set the value of never304="false"

如果要启用httpcache需要配置,如下:

<httpCaching never304="false" >
         <cacheControl>max-age=30, public</cacheControl> 
       </httpCaching>

max-age:缓存时间,以秒为单位
public:所有资源都应用

  • solr内部实现
    HttpSolrCall源码片段
HttpCacheHeaderUtil.setCacheControlHeader(this.config, resp, reqMethod);
//判断缓存是否有效
        if ((this.config.getHttpCachingConfig().isNever304()) || 
          (!HttpCacheHeaderUtil.doCacheHeaderValidation(this.solrReq, this.req, reqMethod, resp)))
        {
          solrRsp = new SolrQueryResponse();

          SolrRequestInfo.setRequestInfo(new SolrRequestInfo(this.solrReq, solrRsp));
          execute(solrRsp);
          HttpCacheHeaderUtil.checkHttpCachingVeto(solrRsp, resp, reqMethod);
          Iterator headers = solrRsp.httpHeaders();
          while (headers.ha
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值