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


C# Cache.Insert方法代码示例

本文整理汇总了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;
    }
开发者ID:aaronpowell,项目名称:nuget-stats,代码行数:25,代码来源:PackageRepository.cs

示例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;
    }
开发者ID:690312856,项目名称:DIS,代码行数:20,代码来源:FAQ.cs

示例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) => { });
     }
     
 }
开发者ID:LittlePeng,项目名称:ncuhome,代码行数:11,代码来源:Default.aspx.cs

示例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 ] ) );
 }
开发者ID:nintorii,项目名称:Zenject,代码行数:11,代码来源:HashCodeTest.cs

示例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 );
        }
开发者ID:nintorii,项目名称:Zenject,代码行数:30,代码来源:Benchmark.cs


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