Add() public method

public Add ( string key, object value, System.Web.Caching.CacheDependency dependencies, System.DateTime absoluteExpiration, System.TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback ) : object
key string
value object
dependencies System.Web.Caching.CacheDependency
absoluteExpiration System.DateTime
slidingExpiration System.TimeSpan
priority CacheItemPriority
onRemoveCallback CacheItemRemovedCallback
return object
        public static AggregationCategorizationService GetService(Cache cache, String userId)
        {

            try
            {
                if (cache["AggCatService_" + userId] == null)
                {
                    string certificateFile = System.Configuration.ConfigurationManager.AppSettings["PrivateKeyPath"];
                    string password = System.Configuration.ConfigurationManager.AppSettings["PrivateKeyPassword"];
                    X509Certificate2 certificate = new X509Certificate2(certificateFile, password);

                    string consumerKey = System.Configuration.ConfigurationManager.AppSettings["ConsumerKey"];
                    string consumerSecret = System.Configuration.ConfigurationManager.AppSettings["ConsumerSecret"];
                    string issuerId = System.Configuration.ConfigurationManager.AppSettings["SAMLIdentityProviderID"];

                    SamlRequestValidator samlValidator = new SamlRequestValidator(certificate, consumerKey, consumerSecret, issuerId, userId);

                    ServiceContext ctx = new ServiceContext(samlValidator);
                    cache.Add("AggCatService_" + userId, new AggregationCategorizationService(ctx), null, DateTime.Now.AddMinutes(50),
                              Cache.NoSlidingExpiration, CacheItemPriority.High, null);
                }
                return (AggregationCategorizationService)cache["AggCatService_" + userId];
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to create AggCatService: " + ex.Message);
            }
        }
 private void CacheSetting(string settingKey, string settingValue, Cache cache)
 {
     settingValue = settingValue.NullSafe();
     OutputCacheSettingsSection outputCacheSection =
         _configurationAdapter.GetSection<OutputCacheSettingsSection>("system.web/caching/outputCacheSettings");
     if (outputCacheSection.OutputCacheProfiles.Count > 0)
     {
         OutputCacheProfile profile = outputCacheSection.OutputCacheProfiles.Get("SettingsCacheProfile");
         if (null != profile)
         {
             cache.Add(settingCacheKey + settingKey, settingValue, null, Cache.NoAbsoluteExpiration,
                       TimeSpan.FromSeconds(profile.Duration), CacheItemPriority.Normal, null);
         }
     }
 }
Example #3
0
 public static JsonValue AddUser(Cache cache, string email, string firstName, string lastName)
 {
     email = email.ToLower();
     var ret = new JsonObject();
     if (EmailExists(cache, email))
     {
         ret["email"] = email;
         ret["message"] = "Email already exists";
     }
     else
     {
         var cacheItm = new Tuple<string, string>(firstName, lastName);
         cache.Add(email, cacheItm, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 10, 0), CacheItemPriority.Normal, null);
         ret.AsDynamic().email = email;
         ret.AsDynamic().firstName = cacheItm.Item1;
         ret.AsDynamic().lastName = cacheItm.Item2;
         ret.AsDynamic().message = "Added";
     }
     return ret;
 }
Example #4
0
 // 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;
 }
        /// <summary>
        /// 从缓存获取获取实体
        /// </summary>
        /// <param name="id">主键</param>
        public static BaseRoleEntity GetObjectByCache(string systemCode, string id)
        {
            if (string.IsNullOrWhiteSpace(systemCode))
            {
                systemCode = "Base";
            }

            BaseRoleEntity result = null;

            System.Web.Caching.Cache cache = HttpRuntime.Cache;
            string cacheObject             = systemCode + "Role";

            if (!string.IsNullOrEmpty(id))
            {
                cacheObject = systemCode + "Role" + id;
            }
            if (cache != null && cache[cacheObject] == null)
            {
                lock (locker)
                {
                    if (cache != null && cache[cacheObject] == null)
                    {
                        BaseRoleManager manager = new DotNet.Business.BaseRoleManager(BaseRoleEntity.TableName);
                        result = manager.GetObject(id);
                        // 若是空的不用缓存,继续读取实体
                        if (result != null)
                        {
                            cache.Add(cacheObject, result, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero, CacheItemPriority.Normal, null);
                            System.Console.WriteLine(System.DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat) + " cache " + systemCode + " Role " + id);
                        }
                    }
                }
            }
            result = cache[cacheObject] as BaseRoleEntity;
            return(result);
        }
Example #6
0
 public static void Store(string feedUri, object content, Cache cache)
 {
     var cacheKey = CACHE_PREFIX + feedUri;
     cache.Add(cacheKey, content, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 10, 0), CacheItemPriority.Default, null);
 }
Example #7
0
        /// <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());
        }
Example #8
0
 public static void Cache <T>(this System.Web.Caching.Cache cache, string key, T data, long timeInSeconds)
 {
     cache.Add(key, data, null, DateTime.Now.AddSeconds(timeInSeconds), System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.High, null);
 }
Example #9
0
 public static void Add(string key, object value, TimeSpan cacheDuration)
 {
     cache.Add(key, value, null, DateTime.MaxValue, cacheDuration, CacheItemPriority.NotRemovable, null);
 }
Example #10
0
 /// <summary>
 /// 添加缓存,如果存在则抛出异常
 /// </summary>
 /// <param name="argKey"></param>
 /// <param name="argValue"></param>
 /// <returns></returns>
 public static int Add(string argKey, object argValue)
 {
     Cache.Add(argKey, argValue, null, DateTime.MaxValue, System.Web.Caching.Cache.NoSlidingExpiration,
               CacheItemPriority.Default, null);
     return(1);
 }
Example #11
0
 /// <summary>
 /// 添加缓存,如果存在则抛出异常
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value"></param>
 /// <param name="expireTime">过期时间</param>
 /// <returns></returns>
 public static void Add(string key, object value, DateTime expireTime)
 {
     cache.Remove(key);
     cache.Add(key, value, null, expireTime,
               System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.Default, null);
 }