本文整理汇总了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);
}
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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);
}
示例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());
}