Пример #1
0
        public async Task <List <Advertisement> > GetBlogs()
        {
            //var connect = Appsettings.app(new string[] { "AppSettings", "RedisCaching", "ConnectionString" });//按照层级的顺序,依次写出来

            List <Advertisement> blogArticleList = new List <Advertisement>();

            if (_redisCacheManager.Get <object>("Redis.Blog") != null)
            {
                blogArticleList = _redisCacheManager.Get <List <Advertisement> >("Redis.Blog");
            }
            else
            {
                blogArticleList = await _advertisementServices.Query(d => d.Id == 1);

                _redisCacheManager.Set("Redis.Blog", blogArticleList, TimeSpan.FromHours(2));//缓存2小时
            }


            return(await _advertisementServices.GetBlogs());
        }