Beispiel #1
0
        /// <summary>
        /// 根据资源类型ID和版本ID获取
        /// </summary>
        public ActionResult GetList(Guid moduleId, string versionIds)
        {
            var versions = versionIds.Split(',').Select(t => Convert.ToInt64(t)).ToArray();

            if (!versions.Any())
            {
                return(Json(new ReturnResult(1, "无效的资源"), JsonRequestBehavior.AllowGet));
            }

            DateTime d1  = DateTime.Now;
            var      key = string.Concat(string.Concat("_preview_resource_getlist_", moduleId, "_", string.Join("_", versionIds)));

            //获取缓存的数据
            //var cacheContent = RedisHelper.GetItemFromSet<string>(key).FirstOrDefault();
            var cacheContent = RedisHelper.GetItem <string>(key);

            if (!string.IsNullOrEmpty(cacheContent))
            {
                //记录redis服务器用时.
                Response.Headers.Add("Redis-Total-Milliseconds", (DateTime.Now - d1).TotalMilliseconds.ToString());
                return(Content(cacheContent, "application/json"));
            }

            if (moduleId == ResourceModuleOptions.ExaminationPaper) //试卷
            {
                cacheContent = JSONHelper.Encode(resourceService.GetExamination(versions[0]));
            }
            else if (moduleId == ResourceModuleOptions.Question)//试题
            {
                cacheContent = JSONHelper.Encode(resourceService.GetQuestions(versions));
            }
            else
            {
                cacheContent = resourceService.GetByVersionIds(moduleId, versionIds);
            }

            if (!string.IsNullOrEmpty(cacheContent) && cacheContent.Contains("\"ret\":0"))
            {
                RedisHelper.SetItem <string>(key, cacheContent, 432000);//设置缓存时间(s)
            }

            return(Content(cacheContent, "application/json"));
        }