gpt4 book ai didi

ASP.NET 捆绑缓存 - 在哪里以及多长时间?

转载 作者:行者123 更新时间:2023-12-01 10:01:11 25 4
gpt4 key购买 nike

在使用新的捆绑和缩小功能对 ASP.NET 应用程序中的性能问题进行故障排除时,我注意到有相当多的文件事件在访问 bundle 中使用的 javascript 文件。

在一个干净的 MVC 应用程序上进行了一些测试后,我注意到在第一次请求之后,我希望它读取文件以构建 bundle ,但它并没有在后续请求中读取文件大约分钟左右。然后它会再次读入它们,然后再安静一分钟左右。

显然这里进行了某种缓存,但是包内容被缓存在哪里以及缓存多长时间?我可以通过配置控制该时间量吗?

最佳答案

响应缓存在 HttpContext.Cache 中,通过使用用于生成包的文件对 VirtualPathProvider 调用带有 CacheDepedency 设置的 Insert。

/// <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);
}

关于ASP.NET 捆绑缓存 - 在哪里以及多长时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15928336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com