// Executed at runtime, before the method. public override void OnEntry(MethodExecutionArgs eventArgs) { // Compose the cache key. string key = _formatStrings.Format( eventArgs.Instance, eventArgs.Method, eventArgs.Arguments.ToArray()); // Test whether the cache contains the current method call. var value = Cache.Get(key); if (ReferenceEquals(value, null)) { lock (Cache) { value = Cache.Get(key); if (ReferenceEquals(value, null)) { // If not, we will continue the execution as normally. // We store the key in a state variable to have it in the OnExit method. eventArgs.MethodExecutionTag = key; } else { // If it is in cache, we set the cached value as the return value // and we force the method to return immediately. eventArgs.ReturnValue = value; eventArgs.FlowBehavior = FlowBehavior.Return; } } } else { eventArgs.ReturnValue = value; eventArgs.FlowBehavior = FlowBehavior.Return; } }
/// <summary> /// 返回一个指定的对象 /// </summary> /// <param name="objId">对象的关键字</param> /// <returns>获取缓存的对象</returns> public virtual object RetrieveObject(string objId) { if (objId == null || objId.Length == 0) { return(null); } return(webCache.Get(objId)); }
/// <summary> /// 是否存在指定缓存对象 /// </summary> /// <param name="objId"></param> /// <returns></returns> public bool IsExist(string objId) { if (webCache == null) { return(false); } return(webCache.Get(objId) == null ? false : true); }
public virtual T Get(string key) { if (string.IsNullOrEmpty(key)) { return(null); } return(cache.Get(key) as T); }
/// <summary> /// 返回一个指定的对象 /// </summary> /// <param name="objId">对象的关键字</param> /// <returns>对象</returns> public object RetrieveObject(string objId) { if (objId == null || objId.Length == 0) { return(null); } object o = webCacheforfocus.Get(objId); return(webCacheforfocus.Get(objId)); }
/// <summary> /// Returns a cache item by key, does not update the cache if it isn't there. /// </summary> /// <typeparam name="TT"></typeparam> /// <param name="cacheKey"></param> /// <returns></returns> public override TT GetCacheItem <TT>(string cacheKey) { var result = _cache.Get(cacheKey); if (result == null) { return(default(TT)); } return(result.TryConvertTo <TT>().Result); }
//若包含其他需要累加 public Somebiz(SysEnvironmentSerialize _envirObj) { string _currlang = _envirObj.I18nCurrLang; System.Web.Caching.Cache currCache = HttpRuntime.Cache; //当前缓存 string defaultlang = APPConfig.GetAPPConfig().GetConfigValue("currlang", ""); //默认语种 this.envirObj = _envirObj; #region 通用语言包 DataTable comlangtmp = (DataTable)currCache.Get("i18nCommonCurrLang"); if (comlangtmp != null) { if (defaultlang == _currlang) { i18nCommonCurrLang = comlangtmp; } else { string commoni18nLangPath = string.Format(APPConfig.GetAPPConfig().GetConfigValue("Commoni18nLang", ""), _currlang); i18nCommonCurrLang = BaseServiceUtility.GetI18nLang(commoni18nLangPath); } } else { string commoni18nLangPath = string.Format(APPConfig.GetAPPConfig().GetConfigValue("Commoni18nLang", ""), _currlang); i18nCommonCurrLang = BaseServiceUtility.GetI18nLang(commoni18nLangPath); } #endregion #region Somebiz语言包 DataTable servFrameSecuriylangtmp = (DataTable)currCache.Get("i18nXxxi18nLang"); if (servFrameSecuriylangtmp != null) { if (defaultlang == _currlang) { i18nXxxManageri18nLang = servFrameSecuriylangtmp; } else { string Somebizi18nLang = string.Format(this.baseXmlPath + APPConfig.GetAPPConfig().GetConfigValue("XxxManageri18nLang", ""), _currlang); i18nXxxManageri18nLang = BaseServiceUtility.GetI18nLang(Somebizi18nLang); } } else { string Somebizi18nLang = string.Format(this.baseXmlPath + APPConfig.GetAPPConfig().GetConfigValue("XxxManageri18nLang", ""), _currlang); i18nXxxManageri18nLang = BaseServiceUtility.GetI18nLang(Somebizi18nLang); } #endregion }
/// <summary> /// 是否存在指定键值的缓存项 /// </summary> /// <param name="key">缓存项键</param> /// <returns>存在返回True</returns> public override bool Contains(string key) { object obj = cache.Get(key); if (obj == null) { return(false); } return(true); }
/// <summary> /// 向缓存中添加一个对象。 /// </summary> /// <param name="key">缓存的键值,该值通常是使用缓存机制的方法的名称。</param> /// <param name="valKey">缓存值的键值,该值通常是由使用缓存机制的方法的参数值所产生。</param> /// <param name="value">需要缓存的对象。</param> public void Add(string key, string valKey, object value) { Dictionary<string, object> dict = null; if (_cacheManager.Get(key) != null) { dict = (Dictionary<string, object>)_cacheManager[key]; dict[valKey] = value; } else { dict = new Dictionary<string, object>(); dict.Add(valKey, value); } _cacheManager.Insert(key, dict); }
/// <summary> /// Retrieves the specified item from the cache. /// </summary> /// <param name="key"></param> /// <returns></returns> public override object Get(string key) { object result = _Cache.Get(key); if (result == null) { cacheLog.Info("索引" + key + "在本地内存中没有值"); return(null); } string ServerInfo = "<div style=\"display:none;\">LOCAL</div>"; ServerInfo += "</body>"; result = result.ToString().Replace("</body>", ServerInfo); return(result); }
public override T Get <T>(string key, long CachingSecond, Func <T> data, CacheTypeEnum type, CacheItemRemovedCallback removedCallback) { if (_cache != null) { var result = _cache.Get(key); if (result == null) { if (data != null) { if (type == CacheTypeEnum.Activity) { if (removedCallback != null) { _cache.Add(key, data, null, DateTime.Now.AddSeconds(CachingSecond), new TimeSpan(CachingSecond * 10), System.Web.Caching.CacheItemPriority.Default, removedCallback); } else { _cache.Add(key, data, null, DateTime.Now.AddSeconds(CachingSecond), new TimeSpan(CachingSecond * 10), System.Web.Caching.CacheItemPriority.Default, null); } } else if (type == CacheTypeEnum.OnTime) { if (removedCallback != null) { _cache.Add(key, data, null, DateTime.Now.AddSeconds(CachingSecond), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, removedCallback); } else { _cache.Add(key, data, null, DateTime.Now.AddSeconds(CachingSecond), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, null); } } return((T)_cache.Get(key)); } else { return(default(T)); } } else { if (type == CacheTypeEnum.Once) { _cache.Remove(key); } } } throw new PlatformNotSupportedException("System.Web.HttpRuntime.Cache can be used in this environment! try another way pls."); }
/// <summary> /// Retrieve the cached object using its hierarchical location /// </summary> /// <param name="xpath">hierarchical location of the object in xml document</param> /// <returns>cached object </returns> public static object Get(string xpath) { object o = null; XmlNode node = objectXmlMap.SelectSingleNode(PrepareXpath(xpath)); //if the hierarchical location existed in the xml, retrieve the object //otherwise, return the object as null if (node != null) { string objectId = node.Attributes["objectId"].Value; //retrieve the object through cache strategy // o = cs.RetrieveObject(objectId); o = webCache.Get(objectId); } return(o); }
/// <summary> /// Get the object from the Cache /// </summary> /// <param name="key">the id of the item to get from the cache</param> /// <returns>the item stored in the cache with the id specified by <paramref name="key"/></returns> public object Get(object key) { if (key == null || _isRootItemCached == false) { return(null); } //get the full key to use to locate the item in the cache string cacheKey = GetCacheKey(key); if (log.IsDebugEnabled) { log.DebugFormat("Fetching object '{0}' from the cache.", cacheKey); } object cachedObject = _webCache.Get(cacheKey); if (cachedObject == null) { return(null); } //casting the object to a dictionary entry so we can verify that the item for the correct key was retrieved var entry = (DictionaryEntry)cachedObject; if (key.Equals(entry.Key)) { return(entry.Value); } return(null); }
protected string TryFindViewFromViewModel(Cache cache, object viewModel) { if (viewModel != null) { var viewModelType = viewModel.GetType(); var cacheKey = "ViewModelViewName_" + viewModelType.FullName; var cachedValue = (string)cache.Get(cacheKey); if (cachedValue != null) { return cachedValue != NoVirtualPathCacheValue ? cachedValue : null; } while (viewModelType != typeof(object)) { var viewModelName = viewModelType.Name; var namespacePart = viewModelType.Namespace.Substring("FODT.".Length); var virtualPath = "~/" + namespacePart.Replace(".", "/") + "/" + viewModelName.Replace("ViewModel", "") + ".cshtml"; if (Exists(virtualPath) || VirtualPathProvider.FileExists(virtualPath)) { cache.Insert(cacheKey, virtualPath, null /* dependencies */, Cache.NoAbsoluteExpiration, _defaultCacheTimeSpan); return virtualPath; } viewModelType = viewModelType.BaseType; } // no view found cache.Insert(cacheKey, NoVirtualPathCacheValue, null /* dependencies */, Cache.NoAbsoluteExpiration, _defaultCacheTimeSpan); } return null; }
public static string GetVersionNumber(System.Web.Caching.Cache cache) { const string versionNumberCacheKey = "versionNumber"; string versionNumber = string.Empty; try { versionNumber = (string)cache.Get(versionNumberCacheKey); } catch { } if (string.IsNullOrEmpty(versionNumber)) { const string style = "color:{0};font-weight:{1};"; string colour = "white"; string weight = "normal"; System.Reflection.Assembly executingAssembly = System.Reflection.Assembly.GetExecutingAssembly(); if (executingAssembly != null) { System.Reflection.AssemblyName executingAssemblyName = executingAssembly.GetName(); if (executingAssemblyName != null) { versionNumber = executingAssemblyName.Version.Major + "." + executingAssemblyName.Version.Minor + "." + executingAssemblyName.Version.Build + " "; } } #if DEBUG versionNumber += "DEBUG"; // Two attributes below are Handled via CSS colour = "bddbf2"; weight = "normal"; // Add the database name we are currently connected to. string databaseName = "unknown"; try { using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Orchestrator"].ConnectionString)) { databaseName = con.Database; } } catch {} versionNumber = string.Format("{0} <span>{1}</span>", versionNumber, databaseName); #endif if (versionNumber != string.Empty) { versionNumber = "<span style=\"" + string.Format(style, colour, weight) + "\">v" + versionNumber + "</span>"; try { cache.Insert(versionNumberCacheKey, versionNumber); } catch { } } } return(versionNumber); }
public object Get(object key) { if (key == null) { return null; } string cacheKey = GetCacheKey(key); if (log.IsDebugEnabled) { log.Debug(String.Format("Fetching object '{0}' from the cache.", cacheKey)); } object obj = cache.Get(cacheKey); if (obj == null) { return null; } var de = (DictionaryEntry) obj; if (key.Equals(de.Key)) { return de.Value; } else { return null; } }
/// <summary> /// 返回一个指定的对象 /// </summary> /// <param name="key">键值</param> /// <returns></returns> public static object Retrieve(string key) { if (string.IsNullOrEmpty(key)) { return(null); } return(webCache.Get(key)); }
/// <summary> /// 获取当前应用程序指定CacheKey的Cache值 /// </summary> /// <param name="CacheKey"></param> /// <returns></returns> public static object GetCache(string CacheKey) { if (CacheKey == null || CacheKey.Length == 0) { return(null); } return(webCache.Get(CacheKey)); }
public virtual object RetrieveObject(string objId) { if (string.IsNullOrEmpty(objId)) { return(null); } return(webCache.Get(objId)); }
/// <summary> /// 获取缓存 /// </summary> /// <param name="cacheKey">对象的关键字</param> /// <returns></returns> public object GetCache(string cacheKey) { if (string.IsNullOrEmpty(cacheKey)) { return(null); } return(cache.Get(cacheKey)); }
private IDictionary <string, object> LocalRetrieve(params string[] keys) { Dictionary <string, object> d = new Dictionary <string, object>(); foreach (string key in keys) { if (!String.IsNullOrWhiteSpace(key)) { object o = _Cache.Get(key); if (o != null) { d.Add(key, o); } } } return(d); }
public static object Get(string key) { if (string.IsNullOrEmpty(key)) { return(null); } return(_cache.Get(key)); }
/// <summary> /// 获取缓存对象 /// </summary> /// <param name="key">缓存Key</param> /// <returns>object对象</returns> public static object Get(string key) { if (string.IsNullOrEmpty(key)) { return(null); } key = ConfigHelper.AppSettings(CacheNamePrefix) + key; return(ObjCache.Get(key)); }
internal object Get(string cacheId, string key, CacheGetOptions options) { Platform.CheckForNullReference(key, "key"); Platform.CheckForNullReference(options, "options"); var cacheKey = GetItemCacheKey(cacheId, options.Region, key); var obj = _cache.Get(cacheKey); if (obj == null) { return(null); } var entry = (DictionaryEntry)obj; return(key.Equals(entry.Key) ? entry.Value : null); }
public object GetData(string key) { try { return(cache.Get(key)); } catch (Exception) { } return(null); }
/// <summary> /// 返回一个指定的对象 /// </summary> /// <param name="CacheName">对象的关键字</param> /// <returns>对象</returns> public object RetrieveObject(string CacheName) { if (CacheName == null || CacheName.Length == 0) { return(null); } return(webcache.Get(CacheName)); }
public T Get <T>(string key) { if (string.IsNullOrEmpty(key)) { return(default(T)); } var json = cache.Get(key).ToString(); return(json.FromJsonString <T>()); }
/// <summary> /// 获得指定Key的缓存对象 /// </summary> /// <param name="Key"></param> /// <returns></returns> public static Object Get(string Key) { object objkey = null; if (ObjCache[Key] != null) { objkey = ObjCache.Get(Key); } return(objkey); }
/// <summary> /// 返回一个指定的对象 /// </summary> /// <param name="objId">对象的关键字</param> /// <returns>对象</returns> public object RetrieveObject(string objId) { //return objectTable[objId]; if (objId == null || objId.Length == 0) { return(null); } return(webCache.Get(objId)); }
public override bool Add <T>(string key, T value) { if (cache == null) { return(false); } else { //Insert方法中,如果添加的键已存在,将会进行替换 if (cache.Get(key) == null) { cache.Insert(key, value); return(true); } else { return(false); } } }
/// <summary> /// 设置当前应用程序指定CacheKey的Cache值 /// </summary> /// <param name="cacheKey">缓存Key</param> /// <returns></returns> public static bool IsExist(string cacheKey) { System.Web.Caching.Cache objCache = HttpRuntime.Cache; if (objCache.Get(cacheKey) != null) { return(true); } else { return(false); } }
// GET api/values public IEnumerable<Notizia> Get() { return _wrap.GetHeaderNews(); // System.Web.Caching.Cache cache = new System.Web.Caching.Cache(); // if (cache["HeaderNews"] == null) { var headerNews = _wrap.GetHeaderNews(); if (headerNews != null) { cache.Add("HeaderNews", "Value 1", null, DateTime.Now.AddSeconds(600), Cache.NoSlidingExpiration, CacheItemPriority.High, onRemove); } } if (cache.Get("HeaderNews") != null) { return (Notizia[])cache.Get("HeaderNews"); } // return null; }
public static bool EmailExists(Cache cache, string email) { return (cache.Get(email.ToLower()) != null); }
/// <summary> /// /// </summary> /// <param name="connectionString"></param> /// <param name="cmdType"></param> /// <param name="cmdText"></param> /// <param name="commandParameters"></param> /// <returns></returns> //-------------------------------------------------------------------------------------------------------------- public static SqlDataReader ExecuteCacheReader(string connectionString, CommandType cmdType, string cmdText,string CacheKey, params SqlParameter[] commandParameters) { SqlCommand cmd = new SqlCommand(); SqlConnection conn = new SqlConnection(connectionString); PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters); SqlCacheDependency dependency = new SqlCacheDependency(cmd); SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection); cmd.Parameters.Clear(); Cache cache = new Cache(); cache.Add(CacheKey, "", dependency, System.Web.Caching.Cache.NoAbsoluteExpiration,System.Web.Caching.Cache.NoSlidingExpiration,System.Web.Caching.CacheItemPriority.Default , null); cache.Insert(CacheKey, rdr, dependency); return (SqlDataReader)cache.Get(CacheKey) ; // conn.Close(); // System.Web.HttpContext.Current.Response.Write(ex.Message.ToString()); }
/// <summary> /// Gets the member list. /// </summary> /// <param name="Refresh"> /// if set to <c>true</c> [refresh]. /// </param> /// <param name="ADDomain"> /// The AD domain. /// </param> /// <param name="AppCache"> /// The app cache. /// </param> /// <returns> /// A System.Data.DataTable value... /// </returns> /// <remarks> /// </remarks> public static DataTable GetMemberList(bool Refresh, string ADDomain, Cache AppCache) { // see if we want to refresh, if not, get it from the cache if available if (! Refresh) { var tmp = AppCache.Get("ADUsersAndGroups" + ADDomain); if (tmp != null) { return ((DataSet)tmp).Tables[0]; } } // create dataset using (var ds = new DataSet()) { using (var dt = new DataTable()) { ds.Tables.Add(dt); var dc = new DataColumn("DisplayName", typeof(string)); dt.Columns.Add(dc); dc = new DataColumn("AccountName", typeof(string)); dt.Columns.Add(dc); dc = new DataColumn("AccountType", typeof(string)); dt.Columns.Add(dc); // add built in users first dt.Rows.Add(new object[] { "Admins", "Admins", "group" }); dt.Rows.Add(new object[] { "All Users", "All Users", "group" }); dt.Rows.Add(new object[] { "Authenticated Users", "Authenticated Users", "group" }); dt.Rows.Add(new object[] { "Unauthenticated Users", "Unauthenticated Users", "group" }); // construct root entry using (var rootEntry = GetDomainRoot(ADDomain)) { if (ADDomain.Trim().ToLower().StartsWith("ldap://")) { var DomainName = GetNetbiosName(rootEntry); // get users/groups var mySearcher = new DirectorySearcher(rootEntry); mySearcher.Filter = "(|(objectClass=group)(&(objectClass=user)(objectCategory=person)))"; mySearcher.PropertiesToLoad.Add("cn"); mySearcher.PropertiesToLoad.Add("objectClass"); mySearcher.PropertiesToLoad.Add("sAMAccountName"); SearchResultCollection mySearcherSearchResult; try { mySearcherSearchResult = mySearcher.FindAll(); foreach (SearchResult resEnt in mySearcherSearchResult) { var entry = resEnt.GetDirectoryEntry(); var name = (string)entry.Properties["cn"][0]; var abbreviation = (string)entry.Properties["sAMAccountName"][0]; var accounttype = GetAccountType(entry); dt.Rows.Add( new object[] { name, DomainName + "\\" + abbreviation, accounttype.ToString() }); } } catch { throw new Exception("Could not get users/groups from domain '" + ADDomain + "'."); } } else if (ADDomain.Trim().ToLower().StartsWith("winnt://")) { var DomainName = rootEntry.Name; // Get the users rootEntry.Children.SchemaFilter.Add("user"); foreach (DirectoryEntry user in rootEntry.Children) { var fullname = (string)user.Properties["FullName"][0]; var accountname = user.Name; dt.Rows.Add( new object[] { fullname, DomainName + "\\" + fullname, ADAccountType.user.ToString() }); } // Get the users rootEntry.Children.SchemaFilter.Add("group"); foreach (DirectoryEntry user in rootEntry.Children) { var fullname = user.Name; var accountname = user.Name; dt.Rows.Add( new object[] { fullname, DomainName + "\\" + fullname, ADAccountType.group.ToString() }); } } } // add dataset to the cache AppCache.Insert("ADUsersAndGroups" + ADDomain, ds); // return datatable return dt; } } }
/// <summary> /// get object from cache /// </summary> /// <param name="CacheKey">Cache Key</param> /// <returns>Object</returns> public static object getCache(string CacheKey) { Cache cache = new Cache(); return cache.Get(CacheKey); }