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


C# Cache.Get方法代码示例

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


在下文中一共展示了Cache.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: AddGet_DateTime_ShouldAddAndExpire_Test

        public void AddGet_DateTime_ShouldAddAndExpire_Test()
        {
            Cache cache = new Cache();
            cache.Add(TestKey, TestValue, DateTime.Now + new TimeSpan(0, 0, 1));

            Assert.AreEqual(TestValue, cache.Get<string, string>(TestKey));
            Thread.Sleep(2000);
            Assert.IsNull(cache.Get<string, string>(TestKey));
        }
开发者ID:RejectKid,项目名称:RiotSharp,代码行数:9,代码来源:CacheTest.cs

示例3: Add_ShouldUpdateIfPresent_Test

        public void Add_ShouldUpdateIfPresent_Test()
        {
            Cache cache = new Cache();
            var otherValue = "otherValue";
            cache.Add(TestKey, TestValue, new TimeSpan(0, 0, 1));

            Assert.AreEqual(TestValue, cache.Get<string, string>(TestKey));
            cache.Add(TestKey, otherValue, new TimeSpan(0, 0, 1));
            Assert.AreEqual(otherValue, cache.Get<string, string>(TestKey));
        }
开发者ID:RejectKid,项目名称:RiotSharp,代码行数:10,代码来源:CacheTest.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: Cache_DataAddedAndReceived_ShouldPass

        public void Cache_DataAddedAndReceived_ShouldPass()
        {
            var storage = new AsteriskStorage();
            var datetime = new ChangeableTime();
            var cache = new Cache<int, string>(16,1000,10000,storage,datetime);

            cache.Get(1);
            cache.Get(2);

            Assert.AreEqual("1",cache[1]);
            Assert.AreEqual("2",cache.Get(2));
        }
开发者ID:Confirmit,项目名称:Students,代码行数:12,代码来源:CacheUnitTests.cs

示例6: ShouldReturnResultValueFromDictionaryWhenTypeIsInCache

            public void ShouldReturnResultValueFromDictionaryWhenTypeIsInCache()
            {
                // Given
                var cache = new Cache<Type, Exception>();
                var initialValue = cache.Get(typeof(ArgumentNullException), () => new ArgumentNullException());

                // When
                var value = cache.Get(typeof(ArgumentNullException), () => new ArgumentNullException());

                // Then
                value.Should().BeSameAs(initialValue);
            }
开发者ID:OpenMagic,项目名称:OpenMagic,代码行数:12,代码来源:CacheTests.cs

示例7: Cache_DataAddedAndReceived_ShouldPass

        public void Cache_DataAddedAndReceived_ShouldPass()
        {
            var storage = new AsteriskStorage();
            //datetime -> dateTime
            var datetime = new ChangeableTime(); //this magic number to const
            var cache = new Cache<int, string>(16,1000,10000,storage,datetime);// needs more space

            cache.Get(1);
            cache.Get(2);

            Assert.AreEqual("1",cache[1]);
            Assert.AreEqual("2",cache.Get(2));
        }
开发者ID:Confirmit,项目名称:Students,代码行数:13,代码来源:CacheUnitTests.cs

示例8: should_keep_cache_if_versions_same

        public async Task should_keep_cache_if_versions_same()
        {
            var cacheConfiguration = new CacheConfiguration(1024, 5, 1024, 5);

            var cacheContainer = InitializeCacheContainer();
            var storage = (TestStorage)cacheContainer.Resolve<IStorage>();

            cacheContainer.Register<IVersionProvider, TestVersionProvider>().WithValue("version", new Version(1, 1));

            using (var cache = new Cache(cacheContainer, cacheConfiguration))
            {
                await cache.Initialize();
                //when at least one value set cache is written
                await cache.Set("some_entry", 42);
            }

            //cache should not be cleanued up if versions in storage and executing assembly differ
            cacheContainer.Register<IVersionProvider, TestVersionProvider>().WithValue("version", new Version(1, 1));
            using (var cache = new Cache(cacheContainer, cacheConfiguration))
            {
                await cache.Initialize();
                storage.KeyToStreams.Should().NotBeEmpty();
                cache.Get<Int32>("some_entry").Result.Value.Should().Be(42);
            }
        }
开发者ID:IvanLeonenko,项目名称:windows-cache,代码行数:25,代码来源:When_version_is_stored_in_cache.cs

示例9: AddGet_DateTime_ShouldAdd_Test

        public void AddGet_DateTime_ShouldAdd_Test()
        {
            Cache cache = new Cache();
            cache.Add(TestKey, TestValue, DateTime.Now + new TimeSpan(0, 5, 0));

            Assert.AreEqual(TestValue, cache.Get<string, string>(TestKey));
        }
开发者ID:RejectKid,项目名称:RiotSharp,代码行数:7,代码来源:CacheTest.cs

示例10: AddGet_TimeSpan_ShouldAddToTheCache_Test

        public void AddGet_TimeSpan_ShouldAddToTheCache_Test()
        {
            Cache cache = new Cache();
            cache.Add(TestKey, TestValue, new TimeSpan(0, 5, 0));

            Assert.AreEqual(TestValue, cache.Get<string, string>(TestKey));
        }
开发者ID:RejectKid,项目名称:RiotSharp,代码行数:7,代码来源:CacheTest.cs

示例11: Cache_Get_Item_Key_Should_Return_Item

 public void Cache_Get_Item_Key_Should_Return_Item()
 {
     Cache<string, int> cache = new Cache<string, int>();
     int EXPECTED = 1;
     cache.Add("1", 1);
     Assert.AreEqual(EXPECTED, cache.Get("1"));
 }
开发者ID:rahilkidwai,项目名称:Net.Utility,代码行数:7,代码来源:CacheTests.cs

示例12: Cache_AddedInFull_ShouldPass

        public void Cache_AddedInFull_ShouldPass()
        {
            var storage = new AsteriskStorage();
            var datetime = new ChangeableTime();
            var cache = new Cache<int, string>(2,1000,10000,storage,datetime);

            cache.Get(1);
            datetime.AddTime(300);

            cache.Get(2);

            cache.Get(3);

            Assert.AreEqual("2", cache.Get(2));
            Assert.AreEqual("3", cache[3]);
            Assert.AreEqual("1*", cache.Get(1));
        }
开发者ID:Confirmit,项目名称:Students,代码行数:17,代码来源:CacheUnitTests.cs

示例13: Cache_AddedInFull_ShouldPass

        public void Cache_AddedInFull_ShouldPass()
        {
            var storage = new AsteriskStorage();
            //datetime -> dateTime
            var datetime = new ChangeableTime();//this magic number to const
            var cache = new Cache<int, string>(2,1000,10000,storage,datetime);// needs more space

            cache.Get(1);
            datetime.AddTime(300);

            cache.Get(2);

            cache.Get(3);

            Assert.AreEqual("2", cache.Get(2));
            Assert.AreEqual("3", cache[3]);
            Assert.AreEqual("1*", cache.Get(1));
        }
开发者ID:Confirmit,项目名称:Students,代码行数:18,代码来源:CacheUnitTests.cs

示例14: Main

        public static void Main()
        {
            var _cache = new Cache<string, DateTime>();

            while (true)
            {
                _cache.Get("Time", MethodThatShouldNotBeCalledVeryFrequently, TimeSpan.FromSeconds(2));
            }
        }
开发者ID:kayone,项目名称:Purse,代码行数:9,代码来源:ThrottleSample.cs

示例15: TestCache

 /// <exception cref="System.Exception"></exception>
 public virtual void TestCache()
 {
     int retainCount = 1;
     Cache cache = new Cache<string, Document>(retainCount);
     IDictionary<string, object> props = new Dictionary<string, object>();
     props.Put("foo", "bar");
     Document doc1 = CreateDocumentWithProperties(database, props);
     cache.Put(doc1.GetId(), doc1);
     IDictionary<string, object> props2 = new Dictionary<string, object>();
     props2.Put("foo2", "bar2");
     Document doc2 = CreateDocumentWithProperties(database, props2);
     cache.Put(doc2.GetId(), doc2);
     NUnit.Framework.Assert.IsNotNull(cache.Get(doc1.GetId()));
     NUnit.Framework.Assert.IsNotNull(cache.Get(doc2.GetId()));
     cache.Remove(doc1.GetId());
     NUnit.Framework.Assert.IsNull(cache.Get(doc1.GetId()));
     cache.Clear();
     NUnit.Framework.Assert.IsNull(cache.Get(doc2.GetId()));
 }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:20,代码来源:CacheTest.cs


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