JMeter – HTTP Cache Manager
Web browsers often include some unique features that reduce Internet traffic and network bandwidth usage, thereby speeding up communication between the client and the server. Caching is one such feature. Resources are retrieved from the network during caching so that they can be used in subsequent requests without involving the web server. Performance testing tools must provide caching for real-time performance testing. We’ll only cover JMeter-specific caching, as this is an Apache JMeter course. As you know, JMeter is not a browser, but it does have settings that help simulate browser activity and make the caching test more accurate.
All the materials that make up a website, including HTML files, CSS style sheets, JavaScript scripts, as well as visual images, and other multimedia content, are often cached locally by browsers. When you visit a website again, the browser checks what content has been updated since your last visit and only downloads newer files or content that hasn’t been cached yet. Static resource files (such as HTML, CSS, JS, images, etc.) are not considered during performance tests, and JMeter does not download these static resources unless explicitly configured to do so. If you choose to use their ‘Get All Embedded Resources’ HTTP sampler, you should include the HTTP Cache Manager in your testing strategy.
How to add ‘HTTP Cache Manager’ in the JMeter script?
Follow the below steps:
- Select the ‘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’?
1. Name: to name the element
2. Leave any comments random.
3. Delete the cache after each iteration? The cache is flushed at the beginning of the thread if this option is selected.
4. Cache cleanup can be controlled via thread pool settings: By using this option, you can specify whether a new iteration involves the same user or a new one. It is linked to the “Same user each iteration” option in the Thread group.
5. When processing GET requests, use the Cache-Control/Expires header: The Cache-Control/Expires value is checked against the current time if this option is selected. The sampler returns immediately without getting the URL of the remote server if the request is a GET request and the timestamp is in the future. The purpose here is to mimic browser activity. Simply put, the response body is empty and the requested file or item is not cached if it hasn’t been modified since it was cached.
Maximum number of items in cache, count: The cache manager will cache 5000 items if the default value is used, which is set to 5000. RAM increases as this value increases