须要耐心啊,太急于求成,但愿直接就获得解决方法了...以致于正确方法都已经出现了,我却没有耐心看下去,因此反而又耽误了很多时间....web
项目加载100+张图片,还有一个小的MP4,因此console警告缓存不够apache
org.apache.catalina.webresources.Cache.getResource Unable to add the resource at [/base/1325/WA6144-150x112.jpg] to the cache because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache The background cache eviction process was unable to free [10] percent of the cache for Context [/liuda] - consider increasing the maximum size of the cache. After eviction approximately [11,145] KB of data remained in the cache
反正就是缓存不够了缓存
上面连接是stackoverflow上出现的和我同样的错误,第二个答案成功的解决了这个警告,就是把缓存弄大点。一开始没耐心看答案,直接把代码加进server.xml了,正确的应该是加到context.xmlapp
<Resources cachingAllowed="true" cacheMaxSize="100000" />
做者:我比风更自由
来源:CSDN
原文:https://blog.csdn.net/qq_26684469/article/details/52346667
版权声明:本文为博主原创文章,转载请附上博文连接!ide
一个WebSource是在Web应用程序中的文件或目录。出于性能缘由,Tomcat能够缓存WebSource。默认状况下,静态资源缓存(总共全部资源)的最大值为 10240千字节(10 MB)。在请求webResource时(例如,在加载静态图像时),webResource被加载到缓存中,而后将其称为缓存条目。每一个缓存条目都有一个TTL(生存时间),这是容许缓存条目保留在缓存中的时间。当TTL过时时,缓存条目有资格从缓存中删除。cacheTTL的默认值为5000毫秒(5秒)。性能
加载webResource时,代码会计算缓存的新大小。若是计算的大小大于默认的最大大小,则必须删除一个或多个缓存的条目,不然新大小将超过最大值。所以代码将计算“targetSize”,这是缓存但愿保持的大小(做为最佳值),默认状况下为95%。为了达到此targetSize,必须从缓存中删除/逐出条目。spa
所以,当其TTL过时且还没有达到targetSize时,将删除缓存条目。.net
在尝试经过逐出缓存条目来释放缓存以后日志
所以,若是在尝试释放缓存后,大小仍然超过最大值,它将显示有关没法释放的警告消息:
cache.addFail=Unable to add the resource at [{0}] to the cache for web application [{1}] because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache
所以,正如警告信息所述,问题是
insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache
若是您的Web应用程序在短期(5秒)内加载了大量未缓存的webResources(大约最大缓存,默认为10mb),那么您将收到警告。
所以,若是您使用的Tomcat 8具备与Tomcat 7相同的默认缓存配置,而且您在Tomcat 8中收到警告,那么Tomcat 7的(和个人)缓存设置在没有警告的状况下表现不佳。
有多种解决方案:
经过在Context元素中添加$CATALINA_BASE/conf/context.xml“XXXXX”表明增长的高速缓存大小,以kbytes为单位。默认值为10240(10 MB),所以请设置大于此值的大小。
<Resources cacheMaxSize="XXXXX" />
您必须调整以得到最佳设置。请注意,当您忽然增长流量/资源请求时,问题可能会再次出现。