本文整理汇总了C#中Cache.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# Cache.Insert方法的具体用法?C# Cache.Insert怎么用?C# Cache.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cache
的用法示例。
在下文中一共展示了Cache.Insert方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPackages
public static IList<DataServicePackage> GetPackages(Cache cache)
{
// Try to load if from the cache
var packages = (IList<DataServicePackage>)cache.Get("packages");
// Double check lock
if (packages == null) {
lock (_lockObject) {
packages = (IList<DataServicePackage>)cache.Get("packages");
if (packages == null) {
// If we still don't have anything cached then get the package list and store it.
packages = _repository.GetPackages().AsEnumerable().Cast<DataServicePackage>().ToList();
cache.Insert("packages",
packages,
null,
DateTime.Now + TimeSpan.FromSeconds(20),
Cache.NoSlidingExpiration);
}
}
}
return packages;
}
示例2: GetQuestionCategory
public static DataSet GetQuestionCategory(bool isFlush, Cache cache)
{
DataSet ds;
if (isFlush)
{
ds = FlushQuestionCategoryKey();
cache.Insert(QuestionCategoryKey, ds);
return ds;
}
if (cache.Get(QuestionCategoryKey) == null)
{
ds = FlushQuestionCategoryKey();
cache.Insert(QuestionCategoryKey, ds);
}
else
ds = (DataSet)cache.Get(QuestionCategoryKey);
return ds;
}
示例3: Insert
public void Insert(string key, object obj, double Minutes)
{
Cache cache = new Cache();
if (obj != null)
{
this.Response.Write(cache);
cache.Remove("dd");
cache.Insert(key, obj, null, DateTime.Now.AddMinutes(Minutes), Cache.NoSlidingExpiration, CacheItemPriority.High, (a,b,c) => { });
}
}
示例4: TestCache
public void TestCache()
{
var types = new[] { typeof(A1), typeof(A1) };
var infos = types.Select( t => new CallInfo( t, null, Flags.StaticInstanceAnyVisibility, MemberTypes.Property, "P1", Type.EmptyTypes, null, true ) ).ToList();
var cache = new Cache<CallInfo, object>();
infos.ForEach( ci => cache.Insert( ci, ci ) );
Assert.AreEqual( 1, cache.Count );
Assert.IsNotNull( cache.Get( infos[ 0 ] ) );
Assert.IsNotNull( cache.Get( infos[ 1 ] ) );
Assert.AreEqual( infos[0], cache.Get( infos[ 0 ] ) );
}
示例5: RunDictionaryBenchmark
private static void RunDictionaryBenchmark()
{
int dictionarySize = 1000;
int index = new Random( (int) (DateTime.Now.Ticks % int.MaxValue) ).Next( 0, dictionarySize );
List<string> stringList =
Enumerable.Range( 0, dictionarySize ).Select( s => Path.GetRandomFileName() + Path.GetRandomFileName() )
.ToList();
Dictionary<string, string> stringDictionary = stringList.ToDictionary( s => s, s => s );
var stringCache = new Cache<string, string>();
stringList.ForEach( s => stringCache.Insert( s, s, CacheStrategy.Permanent ) );
string key = stringList[ index ];
var initMap = new Dictionary<string, Action> { };
var actionMap = new Dictionary<string, Action>
{
{ "Dictionary ContainsKey", () => stringDictionary.ContainsKey( key ) },
{ "Dictionary Indexer", () => { var x = stringDictionary[ key ]; } },
{
"Dictionary TryGetValue", () =>
{
string s;
stringDictionary.TryGetValue( key, out s );
}
},
//{"List Contains", () => stringList.Contains( key ) },
//{"List Linq First", () => stringList.First( item => item == key ) },
{ "Cache GetValue", () => stringCache.Get( key ) },
};
Execute( "Dictionary Benchmark", initMap, actionMap );
}