gpt4 book ai didi

asp.net-mvc - 如何缓存 FileContentResult 以提高性能?

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

目前,我有以下操作从我的数据库返回文件(图像、PDF 等):

    //
// GET: /FileManager/GetFile/ID
[OutputCache(Duration = 600, VaryByParam = "ID")]
public ActionResult GetFile(int ID)
{
FileService svc = new FileService(new SqlFileRepository(base.ConnectionString));

KsisOnline.Data.File result = svc.GetFileByID(ID);

return File(result.Data, result.MimeType, result.UploadFileName);
}

我正在使用 OutputCache 属性,但我不知道我是否正确使用它或如何为此目的优化它。

就代码而言,我似乎在 Firefox(3) 中获得了缓存功能,但在 IE(7) 中却没有。由于某种原因,IE 每次都会从数据库请求图像(这显然是致命的错误),我不知道如何修复它。当然 IE 不能正确支持标准,但也许我仍然没有遵循一些首选的缓存约定。我真的很感谢这方面的一些帮助,这样我就可以得到最少的数据库命中和跨浏览器的缓存支持。

编辑:要查看上面的代码的实际效果或使用浏览器/工具自行对其进行分析,请参阅 this link .

最佳答案

尝试使用 ServerAndClient 位置:

[OutputCache(Duration=600,VaryByParam="ID",Location=OutputCacheLocation.ServerAndClient)]

关于asp.net-mvc - 如何缓存 FileContentResult 以提高性能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/796704/

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