I am trying to clear the cache after each http request accomplished in a thread group. I have already used the http_cache manager but not successful.
Also tried to add a beanshell sampler with following code but didn't work
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.
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.
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. See HTTP Caching article for more details.
If you intend to remove cache between requests - simply don't add the HTTP Cache Manager to your Test Plan.
However if you're looking for the way of manually initiating clearing of cache:
sampler
shorthand in JSR223 Test Elements which stands for HTTPSamplerProxy which in its turn has getCacheManager()
function So you would need to add a suitable JSR223 Test Element, ie JSR223 PostProcessor and use the following code:
sampler.getCacheManager().clear()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.