await
尝试获取缓存数据时不要忘记使用。因为您应该等待插入对象完成。
var data =await BlobCache.LocalMachine.GetObject<UserViewModel>("RsponseData");
试试下面的代码:
using System.Reactive.Linq;
namespace AkavacheTest
{
[Activity(Label = "AkavacheTest", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override async void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
BlobCache.ApplicationName = "AkavacheText";
string json = @"{ 'Username': 'Mike','Password': 'Ma'}";
SetContentView(Resource.Layout.Main);
var getData = JsonConvert.DeserializeObject<User>(json);
await BlobCache.LocalMachine.InsertObject("MikeMa", getData);
var myuser = await BlobCache.LocalMachine.GetObject<User>("MikeMa");
System.Console.WriteLine(myuser.Username+"---"+myuser.Password);
}
}
public class User
{
public string Username { get; set; }
public string Password { get; set; }
}
}
你会得到输出: