JMeter – HTTP Cache Manager

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.

In general, a browser caches files locally, including any documents that make up a website, such as HTML files, CSS style sheets, and JavaScript scripts, as well as graphic images and other multimedia content. When you revisit a website, the browser checks which content was updated in the meantime and only downloads updated files or what is not available in the cache. During performance testing, we do not consider static resource files (like HTML, CSS, js, images, etc.) and JMeter does not download these static resources until it is explicitly configured to do so. HTTP Cache Manager must be included in your test plan if you have enabled your HTTP sampler to ‘Retrieve All Embedded Resources’.

How to add ‘HTTP Cache Manager’ in the JMeter script?

Follow the below steps:

  1. Select ‘Test Plan’ node
  2. Right-click on the ‘Test Plan’ node
  3. Hover the mouse on ‘Add’
  4. Hover the mouse on ‘Config Element
  5. Click ‘HTTP Cache Manager’
JMeter - HTTP Cache Manager
Figure 01: Adding HTTP Cache Manager

What are the input fields of ‘HTTP Cache Manager’?

Figure 02: HTTP Cache Manager
  1. Name: To provide element name
  2. Comments: To provide arbitrary comments (if any)
  3. Clear cache each iteration?: If this option is selected, then the cache is cleared at the start of the thread.
  4. 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.
  5. 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.
  6. 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:

Leave a Comment