public ActionResult Index() { var result = WebCacheManager.FromCache("Events::List", () => { return(data.GetAllElements()); }); var model = Mapper.Map <IList <EventViewModel> >(result); return(View(model)); }
public WeChatManagerTests() { #region 测试代码--微信Token string resStr = "{\"access_token\":\"zWtGZHO2EHfig-nBhIUb0XtQrh88kqDXV4RalOUvZi22tFELCKieW30O85aQafsH8DOKX1HS-J1Scb7Bdi7jShgrLg4Jc8_sBxcFuqYnGyf5QplcIZLXwOt7tHlcxDKEJPFaAIAXDT\",\"expires_in\":7200}"; WeChatTokenModel tempTokenM = ConvertManager.JsonToModel <WeChatTokenModel>(resStr); WebCacheManager.Set("MATERALWECHATTOKENKEY", tempTokenM, DateTimeOffset.Now.AddSeconds(tempTokenM.expires_in - 60)); #endregion }
public HttpResponseMessage GetValidateCode() { VerifyCodeManager vcMa = new VerifyCodeManager(); /*背景是否为图片还是纯色*/ vcMa.TextConfigM.BackIsImage = true; /*背景图片路径(BackIsImage==true时生效)*/ vcMa.TextConfigM.ImageBackgroundPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"\Images\ValidateCode"; /*背景颜色库(BackIsImage==false时生效)*/ vcMa.TextConfigM.BackgroundColors.Add(Color.Ivory); /*值颜色库*/ vcMa.TextConfigM.ValueColors.Add(Color.Red); /*文本库(AllowRandomChinese==true时失效)*/ vcMa.TextConfigM.TextLibrary = new List <string> { //"abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "0123456789" }; //vcMa.TextConfigM.TextLibrary.Add("陈明旭中华人民共和国"); /*采用随机中文模式*/ vcMa.TextConfigM.AllowRandomChinese = false; /*值数量*/ vcMa.TextConfigM.ValueCount = 4; /*混淆数量*/ vcMa.TextConfigM.ConfusionCount = 10; /*混淆模式*/ vcMa.TextConfigM.ImageObfuscationTypes = new List <VerifyCodeImageObfuscationType> { /*假值混淆*/ VerifyCodeImageObfuscationType.FalseValue, /*条纹混淆*/ VerifyCodeImageObfuscationType.Stripe }; /*图片大小*/ vcMa.TextConfigM.ImageSize = new Size(120, 30); /*字体大小*/ vcMa.TextConfigM.FontSize = 18; /*获取验证码*/ VerifyCodeModel vcM = vcMa.GetVeifyCodeModel(); if (vcM.Images.Count > 0) { /*验证码的值存入缓存中*/ WebCacheManager.Set(ApplicationManager.VALIDATECODEKEY + vcM.Value, vcM.Value, DateTimeOffset.Now.AddMinutes(5)); using (MemoryStream ms = new MemoryStream()) { vcM.Images[0].Save(ms, ImageFormat.Jpeg); HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(ms.ToArray()) }; result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png"); return(result); } } return(null); }
public ActionResult AddEvent(EventViewModel ev) { if (ModelState.IsValid) { var newEvent = Mapper.Map <EventViewModel, Event>(ev); data.AddElement(newEvent); WebCacheManager.Clear(); } return(RedirectToAction("Index", "Events")); }
private ICacheManager GetCache() { var cfg = new CacheConfig { AutoExpire = true, AutoRemoveDeadItems = true, Duration = 10, Name = "myConfig" }; ICacheManager wcm = new WebCacheManager(cfg); wcm = new HttpCacheManager(cfg); return(wcm); }
public ActionResult Details(string id) { var result = WebCacheManager.FromCache("Events::" + id, () => { return(data.GetElementById(id)); }); if (result == null) { return(RedirectToRoute("Error.NotFound")); } var model = Mapper.Map <Event, EventViewModel>(result); return(View(model)); }
public ActionResult Harness1() { const int TaskCount = 400; const int MaxItems = 10000; const int GetCount = 15000; var cfg = new CacheConfig { AutoExpire = true, AutoRemoveDeadItems = true, Duration = 3, Name = "myConfig" }; ICacheManager cm = new WebCacheManager(cfg); var t = Harness(cm, TaskCount, MaxItems, GetCount); return(Content("<h1>Harness1</h1><br/><h2>Using WebCacheManager</h2><br/>Time taken: " + t)); }