我试图在线程组中完成每个http请求后清除缓存。我已经使用过http_cache管理器,但没有成功。
还尝试使用以下代码添加一个beanshell采样器,但不起作用
import org.apache.jmeter.protocol.http.control.CacheManager;
CacheManager clearCache = ctx.getCurrentSampler().getProperty("HTTPSampler.cache_manager").getObjectValue();
clearCache.clear();
并获得
ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.apache.jmeter.protocol.http.control.CacheManager; CacheManager clear . . . ''
也尝试使用前置/后置处理器,但不起作用。还添加了http标头的变量。
答案 0 :(得分:2)
在每个采样器之后删除缓存没有任何意义,因为您的JMeter脚本行为与实际的浏览器行为不匹配。
HTTP缓存管理器的主要功能是防止重复下载嵌入式资源,例如图像,脚本,字体,样式,如真实浏览器对连续HTTP请求所做的那样。有关更多详细信息,请参见HTTP Caching文章。
如果您打算在请求之间删除缓存-只需不将HTTP缓存管理器添加到测试计划中即可。
但是,如果您正在寻找手动启动清除缓存的方式:
sampler
的简写,代表HTTPSamplerProxy,而HTTPSamplerProxy又具有getCacheManager()
function 因此,您需要添加适当的JSR223测试元素,即JSR223 PostProcessor并使用以下代码:
sampler.getCacheManager().clear()