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


C# DataCache.GetAsync方法代码示例

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


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

示例1: TestGetInvalid

 public void TestGetInvalid ()
 {
     RunAsync (async delegate {
         var cache = new DataCache ();
         var data = await cache.GetAsync<WorkspaceData> (Guid.NewGuid ());
         Assert.IsNull (data);
     });
 }
开发者ID:VDBBjorn,项目名称:toggl_mobile,代码行数:8,代码来源:DataCacheTest.cs

示例2: TestGetHitMultiple

        public void TestGetHitMultiple ()
        {
            RunAsync (async delegate {
                var data = await DataStore.PutAsync (new WorkspaceData () {
                    Name = "Testing",
                });
                var pk = data.Id;

                var cache = new DataCache ();
                var tasks = new List<Task<WorkspaceData>> (10);
                for (var i = 0; i < 2; i++) {
                    tasks.Add (cache.GetAsync<WorkspaceData> (pk));
                    tasks.Add (cache.GetAsync<WorkspaceData> (pk));
                }

                await Task.WhenAll (tasks);
                var results = tasks.Select (t => t.Result);
                data = results.First ();
                Assert.That (results, Has.All.Matches<WorkspaceData> (r => Object.ReferenceEquals (r, data)));
            });
        }
开发者ID:VDBBjorn,项目名称:toggl_mobile,代码行数:21,代码来源:DataCacheTest.cs

示例3: TestGetHit

        public void TestGetHit ()
        {
            RunAsync (async delegate {
                var data = await DataStore.PutAsync (new WorkspaceData () {
                    Name = "Testing",
                });
                var pk = data.Id;

                var cache = new DataCache ();
                data = await cache.GetAsync<WorkspaceData> (pk);
                Assert.IsNotNull (data);
                Assert.AreEqual (pk, data.Id);
                Assert.AreEqual ("Testing", data.Name);
            });
        }
开发者ID:VDBBjorn,项目名称:toggl_mobile,代码行数:15,代码来源:DataCacheTest.cs

示例4: TestTryGetLoading

        public void TestTryGetLoading ()
        {
            RunAsync (async delegate {
                var data = await DataStore.PutAsync (new WorkspaceData () {
                    Name = "Testing",
                });
                var pk = data.Id;

                var cache = new DataCache ();
                cache.GetAsync<WorkspaceData> (pk);

                var success = cache.TryGetCached (pk, out data);
                if (success) {
                    Assert.IsNotNull (data);
                    Assert.Inconclusive ("Data was loaded before we could check that cache was empty. If it happens all the time, there is a problem.");
                } else {
                    Assert.IsNull (data);
                }
            });
        }
开发者ID:VDBBjorn,项目名称:toggl_mobile,代码行数:20,代码来源:DataCacheTest.cs

示例5: TestEvictCached

        public void TestEvictCached ()
        {
            RunAsync (async delegate {
                var data = await DataStore.PutAsync (new WorkspaceData () {
                    Name = "Testing",
                });
                var pk = data.Id;

                var cache = new DataCache ();
                data = await cache.GetAsync<WorkspaceData> (pk);
                Assert.IsNotNull (data);

                await DataStore.DeleteAsync (data);

                var success = cache.TryGetCached (pk, out data);
                Assert.IsFalse (success);
                Assert.IsNull (data);
            });
        }
开发者ID:VDBBjorn,项目名称:toggl_mobile,代码行数:19,代码来源:DataCacheTest.cs

示例6: TestUpdateCached

        public void TestUpdateCached ()
        {
            RunAsync (async delegate {
                var data = await DataStore.PutAsync (new WorkspaceData () {
                    Name = "Testing",
                });
                var pk = data.Id;

                var cache = new DataCache ();
                data = await cache.GetAsync<WorkspaceData> (pk);
                Assert.IsNotNull (data);

                await DataStore.PutAsync (new WorkspaceData () {
                    Id = pk,
                    Name = "Foo",
                });

                var success = cache.TryGetCached (pk, out data);
                Assert.IsTrue (success);
                Assert.IsNotNull (data);
                Assert.AreEqual ("Foo", data.Name);
            });
        }
开发者ID:VDBBjorn,项目名称:toggl_mobile,代码行数:23,代码来源:DataCacheTest.cs

示例7: TestTryGetTrimSize

        public void TestTryGetTrimSize ()
        {
            RunAsync (async delegate {
                var pks = await DataStore.ExecuteInTransactionAsync (ctx => {
                    var ids = new List<Guid> ();

                    for (var i = 0; i < 150; i++) {
                        var ws = ctx.Put (new WorkspaceData () {
                            Name = String.Format ("Space #{0}", i + 1),
                        });
                        ids.Add (ws.Id);
                    }

                    return ids;
                });

                WorkspaceData data;
                var datas = new List<WorkspaceData> ();
                var cache = new DataCache (100, TimeSpan.FromMinutes (5));
                foreach (var pk in pks) {
                    data = await cache.GetAsync<WorkspaceData> (pk);
                    Assert.NotNull (data);

                    datas.Add (data);
                }

                var success = cache.TryGetCached<WorkspaceData> (pks.First (), out data);
                Assert.IsFalse (success);

                success = cache.TryGetCached<WorkspaceData> (pks.Last (), out data);
                Assert.IsTrue (success);
            });
        }
开发者ID:VDBBjorn,项目名称:toggl_mobile,代码行数:33,代码来源:DataCacheTest.cs


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