public void Does_Not_Cache_Exceptions() { var counter = 0; object result; try { result = AppCache.Get("Blah", () => { counter++; throw new Exception("Do not cache this"); }); } catch (Exception) {} try { result = AppCache.Get("Blah", () => { counter++; throw new Exception("Do not cache this"); }); } catch (Exception) {} Assert.Greater(counter, 1); }
public void Throws_On_Reentry() { // don't run for DictionaryAppCache - not making sense if (GetType() == typeof(DictionaryAppCacheTests)) { Assert.Ignore("Do not run for DictionaryAppCache."); } Exception exception = null; var result = AppCache.Get("blah", () => { try { var result2 = AppCache.Get("blah"); } catch (Exception e) { exception = e; } return("value"); }); Assert.IsNotNull(exception); Assert.IsAssignableFrom <InvalidOperationException>(exception); }
public void Can_Add_When_Not_Available() { var cacheContent1 = new MacroCacheContent(); AppCache.Get("Test1", () => cacheContent1); Assert.AreEqual(1, GetTotalItemCount); }
public void Can_Get_When_Available() { var cacheContent1 = new MacroCacheContent(); var result = AppCache.Get("Test1", () => cacheContent1); var result2 = AppCache.Get("Test1", () => cacheContent1); Assert.AreEqual(1, GetTotalItemCount); Assert.AreEqual(result, result2); }
protected DataSet GetDataList() { if (AppCache.IsExist("SysMenuList")) { ds = (DataSet)AppCache.Get("SysMenuList"); } else { ds = bll.GetList(""); AppCache.AddCache("SysMenuList", ds); } return(ds); }
//操作缓存 public DataTable GetModuleActionFromCache() { if (AppCache.IsExist("ModuleActionCache")) { return((DataTable)AppCache.Get("ModuleActionCache")); } else { DataTable dt = GetList("ACTIONAll", Utils.getOneParams("")); AppCache.AddCache("ModuleActionCache", dt, 1440); return(dt); } }
//用户组角色 public DataTable GetUserGroupRoleFromCache() { if (AppCache.IsExist("UserGroupRoleCache")) { return((DataTable)AppCache.Get("UserGroupRoleCache")); } else { DataTable dt = GetList("GROUPROLEAll", Utils.getOneParams("")); AppCache.AddCache("UserGroupRoleCache", dt, 1440); return(dt); } }
//从缓存中获取K_SysModule表 public DataTable GetModeFromCache() { if (AppCache.IsExist("ModeCache")) { return((DataTable)AppCache.Get("ModeCache")); } else { DataTable dt = GetList("Cache", Utils.getOneParams("")); AppCache.Add("ModeCache", dt, "K_SysModule"); return(dt); } }
public DataTable GetAccountPermitFromCache() { if (AppCache.IsExist("AccountPermitCache")) { return((DataTable)AppCache.Get("AccountPermitCache")); } else { DataTable dt = GetList("USERPERMITAll", Utils.getOneParams("")); AppCache.AddCache("AccountPermitCache", dt, 1440); return(dt); } }
//从缓存中获取K_SysRolePermit表 public DataTable GetRolePermitFromCache() { if (AppCache.IsExist("RolePermitCache")) { return((DataTable)AppCache.Get("RolePermitCache")); } else { DataTable dt = GetList("Cache", Utils.getOneParams("")); AppCache.Add("RolePermitCache", dt, "K_SysRolePermit"); return(dt); } }
public void Can_Clear_By_Search() { var cacheContent1 = new MacroCacheContent(); var cacheContent2 = new MacroCacheContent(); var cacheContent3 = new MacroCacheContent(); var cacheContent4 = new LiteralControl(); AppCache.Get("Test1", () => cacheContent1); AppCache.Get("Tester2", () => cacheContent2); AppCache.Get("Tes3", () => cacheContent3); AppCache.Get("different4", () => cacheContent4); Assert.AreEqual(4, GetTotalItemCount); AppCache.ClearByKey("Test"); Assert.AreEqual(2, GetTotalItemCount); }
public void Can_Remove_By_Strong_Type() { var cacheContent1 = new MacroCacheContent(); var cacheContent2 = new MacroCacheContent(); var cacheContent3 = new MacroCacheContent(); var cacheContent4 = new LiteralControl(); AppCache.Get("Test1", () => cacheContent1); AppCache.Get("Test2", () => cacheContent2); AppCache.Get("Test3", () => cacheContent3); AppCache.Get("Test4", () => cacheContent4); Assert.AreEqual(4, GetTotalItemCount); AppCache.ClearOfType <MacroCacheContent>(); Assert.AreEqual(1, GetTotalItemCount); }
public void Can_Get_By_Search() { var cacheContent1 = new MacroCacheContent(); var cacheContent2 = new MacroCacheContent(); var cacheContent3 = new MacroCacheContent(); var cacheContent4 = new LiteralControl(); AppCache.Get("Test1", () => cacheContent1); AppCache.Get("Tester2", () => cacheContent2); AppCache.Get("Tes3", () => cacheContent3); AppCache.Get("different4", () => cacheContent4); Assert.AreEqual(4, GetTotalItemCount); var result = AppCache.SearchByKey("Tes"); Assert.AreEqual(3, result.Count()); }
public void Can_Clear_All_Items() { var cacheContent1 = new MacroCacheContent(); var cacheContent2 = new MacroCacheContent(); var cacheContent3 = new MacroCacheContent(); var cacheContent4 = new LiteralControl(); AppCache.Get("Test1", () => cacheContent1); AppCache.Get("Test2", () => cacheContent2); AppCache.Get("Test3", () => cacheContent3); AppCache.Get("Test4", () => cacheContent4); Assert.AreEqual(4, GetTotalItemCount); AppCache.Clear(); Assert.AreEqual(0, GetTotalItemCount); }
public void Can_Clear_By_Expression() { var cacheContent1 = new MacroCacheContent(); var cacheContent2 = new MacroCacheContent(); var cacheContent3 = new MacroCacheContent(); var cacheContent4 = new LiteralControl(); AppCache.Get("TTes1t", () => cacheContent1); AppCache.Get("Tester2", () => cacheContent2); AppCache.Get("Tes3", () => cacheContent3); AppCache.Get("different4", () => cacheContent4); Assert.AreEqual(4, GetTotalItemCount); AppCache.ClearByRegex("^\\w+es\\d.*"); Assert.AreEqual(2, GetTotalItemCount); }
public void Can_Remove_By_Type_Name() { var cacheContent1 = new MacroCacheContent(); var cacheContent2 = new MacroCacheContent(); var cacheContent3 = new MacroCacheContent(); var cacheContent4 = new LiteralControl(); AppCache.Get("Test1", () => cacheContent1); AppCache.Get("Test2", () => cacheContent2); AppCache.Get("Test3", () => cacheContent3); AppCache.Get("Test4", () => cacheContent4); Assert.AreEqual(4, GetTotalItemCount); //Provider.ClearCacheObjectTypes("umbraco.MacroCacheContent"); AppCache.ClearOfType(typeof(MacroCacheContent).ToString()); Assert.AreEqual(1, GetTotalItemCount); }
public void Ensures_Delegate_Result_Is_Cached_Once() { var counter = 0; object result; result = AppCache.Get("Blah", () => { counter++; return(""); }); result = AppCache.Get("Blah", () => { counter++; return(""); }); Assert.AreEqual(1, counter); }
/// <summary> /// 取出所有权限,放入cache /// </summary> /// <returns></returns> public DataTable GetMemberCompetenceAll() { DataTable dt = new DataTable(); try { if (AppCache.IsExist("MemberCompetenceAll")) { dt = (DataTable)AppCache.Get("MemberCompetenceAll"); } else { dt = dal.GetList("PCode,ManageTypeID,MemberGradeID", "SystemPermissionTab", ""); AppCache.AddCache("MemberCompetenceAll", dt, 24); } } catch { dt = null; } return dt; }
/// <summary> /// 获取所有菜单,采用缓存cache /// </summary> /// <returns></returns> public DataTable GetMenuCompetence() { DataTable dt = new DataTable(); try { if (AppCache.IsExist("MemberMenu")) { dt = (DataTable)AppCache.Get("MemberMenu"); } else { dt = dal.GetList("*", "MenuTab", "where MCheck=1 and MCode like 'M%' order by Sort "); AppCache.AddCache("MemberMenu", dt, 24) ; } } catch { dt = null; } return dt; }
/// <summary> /// 获取菜单个 /// </summary> /// <returns></returns> public DataTable GetSysmenu() { DataTable dt = new DataTable(); try { if (AppCache.IsExist("SysmenuList")) { dt = (DataTable)AppCache.Get("SysmenuList"); } else { dt = bll.GetList("sysmenutab", " scode,surl ", "scode", 1000, 1, 0, 0, ""); AppCache.AddCache("SysmenuList", dt, 1); } } catch { dt = null; } return(dt); }
/// <summary> /// 获取权限表 /// </summary> /// <returns></returns> public DataTable GetSyspermission() { DataTable dt = new DataTable(); try { if (AppCache.IsExist("SyspermissionList")) { dt = (DataTable)AppCache.Get("SyspermissionList"); } else { dt = bll.GetList("syspermissiontab", " roleid,spcode ", "roleid", 1000, 1, 0, 0, ""); AppCache.AddCache("SyspermissionList", dt, 1); } } catch { dt = null; } return(dt); }
/// <summary> /// 获取用户组,采用缓存cache /// </summary> /// <returns></returns> public DataTable GetSystem() { DataTable dt = new DataTable(); try { if (AppCache.IsExist("SystemList")) { dt = (DataTable)AppCache.Get("SystemList"); } else { dt = bll.GetList("system", "employeeid,tem", "employeeid", 1000, 1, 0, 0, ""); AppCache.AddCache("SystemList", dt, 1); } } catch { dt = null; } return(dt); }
protected void Page_Load(object sender, EventArgs e) { string fileExt = string.Empty; string fileName = string.Empty; string originalName = null; Response.ContentType = "text/plain"; Response.Expires = -1; //如果设置了水印和缩略图,则先将设置保存到cache,在上传图片 string paramValue = Request["paramValue"]; string paramKey = Request["paramKey"]; if (!string.IsNullOrEmpty(paramValue) && !string.IsNullOrEmpty(paramKey)) { AppCache.AddCache(paramKey, paramValue, 60); Response.Write("OK"); return; } //图片上传 try { HttpPostedFile postedFile = Request.Files[0]; SiteDir = GetUrlParam("SiteDir"); string saveType = GetUrlParam("SaveType"); string key = GetUrlParam("param1"); string ImgSet = GetUrlParam("param2"); if (!string.IsNullOrEmpty(key) && AppCache.IsExist(key)) { ImgSet = AppCache.Get(key).ToString(); } if (string.IsNullOrEmpty(ImgSet)) { ImgSet = "0,0,0"; // } string[] arrImgSet = ImgSet.Split(','); thumbWidth = Utils.ParseInt(arrImgSet[0], 0); thumbHeight = Utils.ParseInt(arrImgSet[1], 0); IsWater = Utils.ParseInt(arrImgSet[2], 0); string UPType = GetUrlParam("UpType"); fileName = postedFile.FileName; originalName = fileName; fileExt = Path.GetExtension(fileName).ToLower(); string saveName = DateTime.Now.ToString("yyyyMMddhhmmsfff"); // 上传文件名 if (string.IsNullOrEmpty(UPType)) { UPType = "image"; } uploadobj = KingTop.Config.Upload.GetConfig(GetUploadImgPath); //上传设置信息 if (uploadobj.IsEnableUpload != "1") // 判断是否允许上传 { state = "已经关闭上传功能,请联系管理员"; } SavePath = "{0}"; //文件保存在站点目录下,用下面代码,注释后将不分站点保存 //if (!string.IsNullOrEmpty(SiteDir)) //{ // SavePath += "/" + SiteDir; //} SavePath += "{1}"; switch (UPType) { case "media": //视频,flash SavePath = string.Format(SavePath, uploadobj.MediaSavePath, "/Medias"); URL = GetUploadUrl(uploadobj.MediaUrl, "Medias", SavePath); AllowExt = "*.wav;*.avi;*.mpg;*.mpeg;*.wma;*.flv;*.swf"; MaxSize = 100; break; case "file": //文件 SavePath = string.Format(SavePath, uploadobj.FileSavePath, "/Files"); URL = GetUploadUrl(uploadobj.FileUrl, "Files", SavePath); AllowExt = uploadobj.UploadFilesType; break; case "image": //图片 SavePath = string.Format(SavePath, uploadobj.ImageSavePath, "/Images"); URL = GetUploadUrl(uploadobj.ImageUrl, "Images", SavePath); AllowExt = uploadobj.UploadImageType; break; case "flash": //flash SavePath = string.Format(SavePath, uploadobj.MediaSavePath, "/Medias"); URL = GetUploadUrl(uploadobj.MediaUrl, "Medias", SavePath); AllowExt = uploadobj.UploadMediaType; break; default: break; } if (AllowExt.IndexOf(fileExt.Replace(".", "")) == -1) { state = "文件类型不允许上传!"; } if (SystemConst.NOT_ALLOWED_UPLOAD_TYPE.IndexOf(fileExt.Replace(".", "")) != -1) { state = "文件类型不允许上传!"; } if (postedFile.ContentLength > MaxSize * 1024 * 1024) { state = "文件大小超出网站限制!"; } string reFilePath = URL; // 返回文件路径,如果保存路径填写的是绝对地址,则返回文件路径为域名+系统创建路径,如果为相对地址,则为:域名+相对路径+系统创建路径 if (SavePath.IndexOf(":") == -1) //判断输入的是虚拟路径 { SavePath = Server.MapPath(GetVirtualPath + SavePath); } SavePath = SavePath + "/" + DateTime.Now.Year + "/" + DateTime.Now.Month + "/"; if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } if (saveType == "1") //使用原文件名进行保存到服务器 { int fileNameLength = fileName.LastIndexOf("."); saveName = fileName.Substring(0, fileNameLength); } fileName = SavePath + saveName + fileExt; URL += DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + saveName + fileExt; if (File.Exists(fileName) && saveType == "1") { File.Delete(fileName); } postedFile.SaveAs(fileName); //保存至服务器 if (thumbWidth > 0 || thumbHeight > 0) //判断是否上传的是否需生成缩略图 { string thumbMode = "HW"; if (thumbWidth > 0 && thumbHeight == 0) { thumbMode = "W"; } else if (thumbWidth == 0 && thumbHeight > 0) { thumbMode = "H"; } KingTop.WEB.SysAdmin.UploadBase.MakeThumbnail(fileName, fileName + ".gif", thumbWidth, thumbHeight, thumbMode); // 生成缩略图方法 } if (IsWater == 1) //如果上传图片,则判断是否需要打水印 { KingTop.WEB.SysAdmin.UploadBase.ImageWater(uploadobj, fileName); } } catch (Exception ex) { state = ex.Message; } if (Request["action"] == "tmpImg") { Response.Write("<script>alert('bbbb');parent.ue_callback('" + URL + "','" + state + "')</script>");//回调函数 } else { Response.Write("{'state':'" + state + "','url':'" + URL + "','fileType':'" + fileExt + "','original':'" + originalName + "'}"); //向浏览器返回数据json数据 } }
private void On_Upload(HttpPostedFile file) { if (file != null && file.ContentLength > 0) { #region 变量 strParam = Request.QueryString["InitParam"]; initArr = Utils.strSplit(strParam, "_tp_"); SiteDir = GetUrlParam("SiteDir", initArr); SaveFileKey = GetUrlParam("CacheKey", initArr); string ImgSet = GetUrlParam("ImgSet", initArr); string[] arrImgSet = ImgSet.Split(','); thumbWidth = Utils.ParseInt(arrImgSet[0], 0); thumbHeight = Utils.ParseInt(arrImgSet[1], 0); IsWater = Utils.ParseInt(arrImgSet[2], 0); string UPType = GetUrlParam("UpType", initArr); if (string.IsNullOrEmpty(UPType)) { UPType = "image"; } string saveType = GetUrlParam("SaveType", initArr); // 保存文件名类型,1=用上传文件名保存,否则用系统时间重命名保存 string noExt = SystemConst.NOT_ALLOWED_UPLOAD_TYPE; // 不允许上传类型 string fileName = string.Empty; // 文件名 string saveName = DateTime.Now.ToString("yyyyMMddHHmmss"); // 上传文件名 string fileExt = string.Empty; // 上传文件扩展名 fileName = Path.GetFileName(file.FileName); fileExt = Path.GetExtension(fileName).ToLower(); //上传文件扩展名 #endregion if (noExt.IndexOf(fileExt) != -1) { System.Web.HttpContext.Current.Response.Write("改文件类型不允许上传!"); System.Web.HttpContext.Current.Response.End(); } SavePath = string.IsNullOrEmpty(SiteDir) == true ? uploadobj.ImageSavePath + "/" + UPType + "s" : uploadobj.ImageSavePath + "/" + SiteDir + "/" + UPType + "s"; URL = GetUploadUrl(uploadobj.ImageUrl, UPType + "s", SavePath); string reFilePath = URL; // 返回文件路径,如果保存路径填写的是 if (SavePath.IndexOf(":") == -1) //判断输入的是虚拟路径 { SavePath = Server.MapPath(GetVirtualPath + SavePath); } SavePath = SavePath + "/" + DateTime.Now.Year + "/" + DateTime.Now.Month + "/"; if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } if (saveType == "1") //使用原文件名进行保存到服务器 { int fileNameLength = fileName.LastIndexOf("."); saveName = fileName.Substring(0, fileNameLength); } fileName = SavePath + saveName + fileExt; URL = DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + saveName + fileExt; if (File.Exists(fileName) && saveType == "1") { File.Delete(fileName); } try { file.SaveAs(fileName); //保存至服务器 if (thumbWidth > 0 || thumbHeight > 0) //判断是否上传的是否需生成缩略图 { string thumbMode = "HW"; if (thumbWidth > 0 && thumbHeight == 0) { thumbMode = "W"; } else if (thumbWidth == 0 && thumbHeight > 0) { thumbMode = "H"; } KingTop.WEB.SysAdmin.UploadBase.MakeThumbnail(fileName, fileName + ".gif", thumbWidth, thumbHeight, thumbMode); // 生成缩略图方法 } if (IsWater == 1) //如果上传图片,则判断是否需要打水印 { KingTop.WEB.SysAdmin.UploadBase.ImageWater(uploadobj, fileName); } } catch (Exception ex) { ex.ToString(); } //缓存返回值 string returnStr; if (AppCache.IsExist(SaveFileKey)) { returnStr = AppCache.Get(SaveFileKey) + "," + URL; AppCache.Remove(SaveFileKey); } else { returnStr = URL; } AppCache.AddCache(SaveFileKey, returnStr, 1200); } }
public object Get(string key) { return(AppCache.Get(key)); }