Bryan
Bryan

Reputation: 3667

How can I turn off request caching in a Visual Studio load test

After running a load test, in the results data, it shows that cached requests accumulate throughout the duration of the test, increasing over time.

In my web test, each URL has the Cache Control setting turned off, which is supposed to mean don't cache.

Furthermore, in my load test scenario settings, I have the "Percentage of New Users" setting set to 100, which means that each user should be treated as a new user, and not use caching.

With these settings, why are the test results still showing the increasing amount of cached requests throughout the load test?

I attached an image of the load test results graph of cached requests for clarification.

Load Test Results graph of cached requests

Upvotes: 3

Views: 5220

Answers (2)

QuranX Administrator
QuranX Administrator

Reputation: 425

Thanks to this blog I created the following class.

using System.ComponentModel;
using Microsoft.VisualStudio.TestTools.WebTesting;

namespace QuranX.Web.LoadTest.WebTestPlugins
{
    [DisplayName("Enable browser caching")]
    public class EnableBrowserCachingPlugin : WebTestPlugin
    {
        [DisplayName("Allow caching")]
        [Description("If True then server responses will be cached")]
        public bool AllowCaching { get; set; } = true;

        public override void PostRequest(object sender, PostRequestEventArgs e)
        {
            foreach (WebTestRequest dependentRequest in e.Request.DependentRequests)
            {
                dependentRequest.Cache = AllowCaching;
            }
        }
    }
}

The instructions then show how to install the plugin.

  1. Build the app
  2. Open the WebTest file
  3. In the icons click "Add Web Test Plugin"
  4. Set the "Enable browser caching" property to false

Upvotes: 0

Cybermaxs
Cybermaxs

Reputation: 24556

As you know, there is a property named “Cache Control” on each request. When the Cache Control property on a request in the Web test is false, the request is always issued. When the Cache Control property is true, the VSTS load test runtime code attempts to emulate the Browser caching behavior.

However, the Cache Control property is automatically set to true for all dependent requests (images, style sheets, javascripts, ...).

In a load test, the browser caching behavior is simulated separately for each user running in the load test. But event if “Percentage of New Users” is set to 100, the cache will be used during the virtual user session. If your web test contains many pages, the cache will be used.

Since VSTS 2008, you can now write a WebTestPlugin that disables caching of all dependent requests.

Note : When running a Web test by itself, the Cache Control property is automatically set to false for all dependent requests so they are always fetched : this allow you to view the html page in the browser.

Upvotes: 5

Related Questions