3

While troubleshooting a performance issue in an ASP.NET app using the new bundling and minification features, and I noticed quite a bit of file activity accessing the javascript files used in the bundles.

After a bit of testing on a clean MVC app, I noticed that after the first request, where I would expect it to read the files to build up the bundle, it didn't read the files on subsequent requests for about a minute or so. Then it would read them in again, and then go quiet for another minute or so.

Obviously there's some kind of caching going on here, but where are the bundle contents getting cached and for how long? And can I control that amount of time through configuration?

Brian Sullivan
  • 27,513
  • 23
  • 77
  • 91

2 Answers2

6

The responses are cached inside of the HttpContext.Cache via a call to Insert with a CacheDepedency setup against the VirtualPathProvider with the files that were used to generate the bundle.

/// <summary>
/// Stores the response for the bundle in the cache, also sets up cache depedencies for the virtual files
/// used for the response
/// </summary>
public void Put(BundleContext context, Bundle bundle, BundleResponse response) {
    List<string> paths = new List<string>();
    paths.AddRange(response.Files.Select(f => f.VirtualFile.VirtualPath));
    paths.AddRange(context.CacheDependencyDirectories);
    string cacheKey = bundle.GetCacheKey(context);
    CacheDependency dep = context.VirtualPathProvider.GetCacheDependency(context.BundleVirtualPath, paths, DateTime.UtcNow);
    context.HttpContext.Cache.Insert(cacheKey, response, dep);
    bundle.CacheKeys.Add(cacheKey);
}
Hao Kung
  • 28,040
  • 6
  • 84
  • 93
1

Turns out I was using pre-release versions of the entire MVC4 stack, including System.Web.Optimization. Upgrading to RTM resolved the issue.

Brian Sullivan
  • 27,513
  • 23
  • 77
  • 91