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


C# DataCache.TryGetCached方法代码示例

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


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

示例1: TestTryGetInvalid

 public void TestTryGetInvalid ()
 {
     var cache = new DataCache ();
     WorkspaceData data;
     var success = cache.TryGetCached (Guid.NewGuid (), out data);
     Assert.IsFalse (success);
     Assert.IsNull (data);
 }
开发者ID:VDBBjorn,项目名称:toggl_mobile,代码行数:8,代码来源:DataCacheTest.cs

示例2: TestTryGetMiss

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

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

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

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

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