[英]How to get the topmost caching in ASP.NET Core?
I'm building a CMS.我正在构建一个 CMS。 Every image would get a GUID.每个图像都会获得一个 GUID。 This means that even if user edit an image, it would be saved with a new GUID.这意味着即使用户编辑图像,它也会使用新的 GUID 保存。
Thus I want to cache the image for the topmost possible cache.因此,我想为最顶层的缓存缓存图像。 In fact I want to cache it forever.事实上,我想永远缓存它。
ASP.NEt Core's Docs has a long list of options. ASP.NEt Core 的文档有一长串选项。
I'm not sure what option gives me the most caching time.我不确定哪个选项给我最多的缓存时间。
What should I do to cache my images forever?我应该怎么做才能永远缓存我的图像?
you can use memoryCache
Caching.Memory and set CacheItemPriority
to NeverRemove
您可以使用memoryCache
Caching.Memory并将CacheItemPriority
设置为NeverRemove
use the memoryCache in .NET Core使用 .NET Core 中的 memoryCache
install Caching.Memory
from nuget.从 nuget 安装Caching.Memory
。
in your Startup.cs file, you need to introduce MemoryCache在你的 Startup.cs 文件中,你需要引入 MemoryCache
services.AddMemoryCache();
inject to Controler注入控制器
public class myContoroler: Controller { private readonly MemoryCache _memoryCache; public myContoroler(IMemoryCache memoryCache) { _memoryCache = memoryCache; } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.