Generally, web browsers have some special features which allow to reduce the traffic over the Internet and also reduce the usage of network bandwidth that makes communication between clients and servers faster than usual. One such feature is called ‘Caching’. In caching, the resources are downloaded from the network, for use in the subsequent requests without triggering the web server. To conduct real-time performance testing caching features should be available in the performance testing tools. Since this is the Apache JMeter tutorial so will discuss Caching related to JMeter only. As you know that JMeter is not a browser but JMeter has one config element which helps to mimic the browser behaviour and make the test more realistic in terms of caching. ‘HTTP Cache Manager’ is used to simulate the browser caching behaviour in JMeter by adding caching functionality to HTTP requests within its scope.
How to add ‘HTTP Cache Manager’ in the JMeter script?
Follow the below steps:
- Select ‘Test Plan’ node
- Right-click on the ‘Test Plan’ node
- Hover the mouse on ‘Add’
- Hover the mouse on ‘Config Element‘
- Click ‘HTTP Cache Manager’
What are the input fields of ‘HTTP Cache Manager’?
- Name: To provide element name
- Comments: To provide arbitrary comments (if any)
- Clear cache each iteration?: If this option is selected, then the cache is cleared at the start of the thread.
- Use Thread Group configuration to control cache clearing: This option provides the ability to configure whether a new iteration is with a new user or with the same user. It is mapped with the option ‘Same user on each iteration’ in the Thread group.
- Use Cache Control/Expires header when processing GET requests: If this option is selected, then the Cache-Control/Expires value is checked against the current time. If the request is a GET request, and the timestamp is in the future, then the sampler returns immediately, without requesting the URL from the remote server. This is intended to emulate browser behaviour. Simply I can say that if the requested file/component has not changed since it was cached, then the response body will be empty and it will be taken from the cache.
- Max Number of elements in cache: By default value is set to 5000 which indicates that the cache manager will store 5000 items in the cache. As much as you increase this value, the memory will be consumed more and JMeter may throw an “out of memory” exception.
You may be interested: