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