本文整理汇总了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);
});
}
示例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)));
});
}
示例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);
});
}
示例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);
}
});
}
示例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);
});
}
示例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);
});
}
示例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);
});
}