c# - 如何使用.net core 实现图像缓存?
问题描述
我想缓存我的图像并找到类似的东西
<cache enabled="true">
Current Time Inside Cache Tag Helper: @DateTime.Now
</cache>
解决方案
图片缓存是客户端缓存,您应该像下面这样配置您的应用程序:
app.UseStaticFiles(new StaticFileOptions
{
ServeUnknownFileTypes = false,
OnPrepareResponse = ctx =>
{
const int durationInSeconds = 60 * 60 * 24;
ctx.Context.Response.Headers[HeaderNames.CacheControl] = "public,max-age=" + durationInSeconds;
ctx.Context.Response.Headers[HeaderNames.Expires] = new[] { DateTime.UtcNow.AddYears(1).ToString("R") }; // Format RFC1123
}
});
推荐阅读
- c++ - 如何使用 cmake 编译可以在 Windows 系统上运行的应用程序
- django - django 中的 Is_popup 选项似乎不起作用
- python - 我怎样才能得到一个对象?
- audio - ffmpeg:从 mp4 视频中提取的 wav 与原始视频的持续时间不同
- jpa - Spring JPA:找不到能够从类型 [java.lang.String] 转换为 Java 类型的转换器
- php - authentification facebook : Invalid App ID 提供的 App ID 似乎无效
- python - Python 尝试/最终使用 sys.exc_info()
- microsoft-graph-api - Microsoft Graph 中的 Bookings API - OptOutOfCustomerEmail = true 会导致发送确认电子邮件
- sql - 如何根据另一个表从一个表中获取数据?
- node.js - 使用 npm-registry-client 发布包时出错