我是 Redis 缓存实现的新手,使用 Redis 缓存中的 getstring
获得了一个简单的示例,它工作正常。但同时我对通过 Redis 设置和获取列表值一无所知。
我有使用提供者和存储库。请帮助我如何进一步进行...
public List<Article> GetArticleListBySectionName(string sectionName, int RegionId, int Count, int CacheTime, string cacheKey, bool cacheEnable = false, string expiryInMinutes = "NoExpiry")
{
{
cacheKey = GetCacheKey(cacheKey, Convert.ToString(sectionName));
List<Article> _article = _cacheProxy.Get<List<Article>>(cacheKey);
if (_article != null)
{
_article = _articleRepositary.GetArticleListBySectionName(sectionName, RegionId, Count, CacheTime);
_cacheProxy.Store<List<Article>>(_article, cacheKey, expiryInMinutes);
}
return _article;
}
}
此处 _cacheProxy.Get
和 _cacheProxy.Store
获取 null
值..执行此操作时,我会收到错误页面
最佳答案
- 注入(inject)依赖
在WebApiConfig 中添加以下行
config.DependencyResolver = new UnityResolver(Bootstrapper.Initialise(DIContainer.Initialise()));
- 添加
127.0.0.1:6379
的 Redis 端点
关于asp.net-web-api - 如何在带有存储库的 Web Api 中使用 Redis 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48536243/