asp.net-web-api - 如何在带有存储库的 Web Api 中使用 Redis 缓存

标签 asp.net-web-api redis

我是 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 值..执行此操作时,我会收到错误页面

最佳答案

  1. 注入(inject)依赖
  2. 在WebApiConfig 中添加以下行

    config.DependencyResolver = new UnityResolver(Bootstrapper.Initialise(DIContainer.Initialise()));

  3. 添加 127.0.0.1:6379
  4. 的 Redis 端点

关于asp.net-web-api - 如何在带有存储库的 Web Api 中使用 Redis 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48536243/

相关文章:

angularjs - 来自 Angular 的 415 错误 Web Api POST

javascript - Node js 和 Redis 未定义的 JSON 属性

redis - 带有 redis 的 phpspreadsheet 增加了运行时间

Redis pub sub max 订阅者和发布者

scala - 强制Redis超时

c# - 身份验证 token 提供者 : Custom error message

c# - 获取url中所有参数

asp.net - “System.Net.Http.HttpContent”不包含 'ReadAsAsync' 的定义并且没有扩展方法

php - 需要以更快的方式将用户信息存储到 Redis 中,正确的命令是什么? (为了获得更好的表现)

c# - 浏览器OPTIONS请求方式和windows授权