当前位置: 首页>>代码示例>>C#>>正文


C# Cache.Add方法代码示例

本文整理汇总了C#中System.Web.Caching.Cache.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Cache.Add方法的具体用法?C# Cache.Add怎么用?C# Cache.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Caching.Cache的用法示例。


在下文中一共展示了Cache.Add方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetService

        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);
            }
        }
开发者ID:tarandhupar,项目名称:IPP_Sample_Code,代码行数:28,代码来源:AggCatService.cs

示例2: CacheSetting

 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);
         }
     }
 }
开发者ID:MasroorKhalid,项目名称:AtomicCms,代码行数:15,代码来源:SettingService.cs

示例3: AddUser

 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;
 }
开发者ID:axshon,项目名称:HTML-5-Ellipse-Tours,代码行数:20,代码来源:CacheRepo.cs

示例4: Get

 // 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;
 }
开发者ID:Rimysoft,项目名称:OlbiaNovaAPI,代码行数:22,代码来源:TopController.cs

示例5: Store

 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);
 }
开发者ID:dodyg,项目名称:hobi-hobi,代码行数:5,代码来源:SyndicationFeedCache.cs

示例6: ExecuteCacheReader

        /// <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());
        }
开发者ID:LittlePeng,项目名称:ncuhome,代码行数:26,代码来源:DBHelper.cs


注:本文中的System.Web.Caching.Cache.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。