.netcore使用cache
1 .第一步在项目的startup.cs文件里面的ConfigureServices方法下添加代码 services.AddMemoryCache();
效果如图所示
第二步在控制器添加如下代码:
protected IMemoryCache _cache;
public MerchantController(IMemoryCache memoryCache)
{
_cache = memoryCache;
}
第三步调用:
_cache.Set("temp", m.data);//这是设置cache
var cache = _cache.Get("temp");//这是获取cache
本文介绍了如何在.NET Core项目中使用内存缓存功能。通过在Startup.cs文件中配置服务并注入IMemoryCache接口到控制器中,可以实现数据的缓存与获取。这种做法能有效提高应用程序性能。
590

被折叠的 条评论
为什么被折叠?



