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


C# Cache.Put方法代码示例

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


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

示例1: 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

示例2: GetById_ItemInCache_DataStoreIsntAccessed

        public void GetById_ItemInCache_DataStoreIsntAccessed()
        {
            //Arrange
            var cache = new Cache();
            cache.Put(123, "This is my data is from the cache");

            var storeMock = new Mock<DataStore>() { CallBase = true};
            storeMock.Object.Add(123, "This is my data is from the data store");

            var repository = new Repository(storeMock.Object, cache);

            //Act
            var item = repository.GetById<string>(123);

            //Assert
            Assert.AreEqual("This is my data is from the cache", item);
            storeMock.Verify(x => x.GetById<string>(It.IsAny<int>()), Times.Never);
        }
开发者ID:Fodsuk,项目名称:CloudDesignPatternCodeExamples,代码行数:18,代码来源:RepositoryTests.cs

示例3: GetById_ItemExpiredFromCache_DataStoreIsAccessed

        public void GetById_ItemExpiredFromCache_DataStoreIsAccessed()
        {
            //Arrange
            var cache = new Cache();
            cache.Put(123, "This is my data is from the cache");
            cache.ItemExperationInSeconds = 10;

            var store = new DataStore();
            store.Add(123, "This is my data is from the data store");

            var repository = new Repository(store, cache);

            //Act
            Thread.Sleep(10); //wait 10 seconds for cache to expire
            var item = repository.GetById<string>(123);

            //Assert
            Assert.AreEqual("This is my data is from the cache", item);
        }
开发者ID:Fodsuk,项目名称:CloudDesignPatternCodeExamples,代码行数:19,代码来源:RepositoryTests.cs


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