首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用.net内核实现图片的缓存?

如何使用.net内核实现图片的缓存?
EN

Stack Overflow用户
提问于 2019-12-09 22:55:01
回答 1查看 1.7K关注 0票数 0

我想缓存我的图像,然后找到类似这样的东西

<cache enabled="true"> Current Time Inside Cache Tag Helper: @DateTime.Now </cache>

https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/cache-tag-helper?view=aspnetcore-3.1我如何在上面实现我的镜像?

EN

回答 1

Stack Overflow用户

发布于 2019-12-14 05:26:38

图片缓存是客户端缓存,你应该像下面这样配置你的应用:

代码语言:javascript
复制
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
                }
            });
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59251391

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档