简体   繁体   English

Jmeter在每个HTTP请求之后清除缓存

[英]Jmeter Clear cache after each http request

I am trying to clear the cache after each http request accomplished in a thread group. 我试图在线程组中完成每个http请求后清除缓存。 I have already used the http_cache manager but not successful. 我已经使用过http_cache管理器,但没有成功。

Also tried to add a beanshell sampler with following code but didn't work 还尝试使用以下代码添加一个beanshell采样器,但是没有用

import org.apache.jmeter.protocol.http.control.CacheManager;

CacheManager clearCache = ctx.getCurrentSampler().getProperty("HTTPSampler.cache_manager").getObjectValue();

clearCache.clear();

And getting 并得到

ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval   Sourced file: inline evaluation of: ``import org.apache.jmeter.protocol.http.control.CacheManager;  CacheManager clear . . . ''

Also tried to use the pre/post-processor, but not working. 也尝试使用前置/后置处理器,但不起作用。 Also added the variable for http header. 还添加了http标头的变量。

Please refer the screenshot attached. 请参考所附的屏幕截图。 header-screenshot 标题屏幕截图 在此处输入图片说明 Thread Group 线程组 在此处输入图片说明 在此处输入图片说明

Removing cache after each sampler doesn't make any sense because your JMeter script behaviour won't match real browsers behaviour. 在每个采样器之后删除缓存没有任何意义,因为您的JMeter脚本行为与实际的浏览器行为不符。

The main feature of the HTTP Cache Manager is preventing repeated downloading of the embedded resources like images, scripts, fonts, styles like real browsers do for consecutive HTTP requests. HTTP缓存管理器的主要功能是防止重复下载嵌入式资源,例如图像,脚本,字体,样式等,就像真实浏览器对连续HTTP请求所做的那样。 See HTTP Caching article for more details. 有关更多详细信息,请参见HTTP缓存文章。

If you intend to remove cache between requests - simply don't add the HTTP Cache Manager to your Test Plan. 如果您打算在请求之间删除缓存-只需不将HTTP缓存管理器添加到测试计划中即可。


However if you're looking for the way of manually initiating clearing of cache: 但是,如果您正在寻找手动启动清除缓存的方法:

So you would need to add a suitable JSR223 Test Element, ie JSR223 PostProcessor and use the following code: 因此,您需要添加一个合适的JSR223测试元素,即JSR223 PostProcessor并使用以下代码:

sampler.getCacheManager().clear()

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM