I Try to load cached data via Akavache, but i dont know why i cant get it right. i try to get FullName and Email that i already cached after login , so i getobject in my "CachedUser" model but dont know why its says there is no definition for FullName and Email in there. Here is my CachedUser Model
namespace KGVC.Models
{
public class CachedUsers
{
public string FullName { get; set; }
public string Email { get; set; }
}
}
and here is the code to getobject in Akavache that i try to implement
public void GetDataCache(object sender, EventArgs e)
{
var loaded = BlobCache.LocalMachine.GetObject<CachedUsers>("usercached");
txtemail.Text = loaded.FullName;
txtfullname.Text = loaded.FullName.ToString();
}
and here is the cache user code
public void CacheUser(AuthenticationResult ar)
{
JObject user = ParseIdToken(ar.IdToken);
var cache = new CachedUsers
{
FullName = user["name"]?.ToString(),
Email = user["emails"]?.ToString()
};
BlobCache.LocalMachine.InsertObject("usercached", cache);
}
and here is the full error message that i get
'IObservable<CachedUsers>' does not contain a definition for 'FullName' and no extension method 'FullName' accepting a first argument of type 'IObservable<CachedUsers>' could be found (are you missing a using directive or an assembly reference?)
what is the problem in here , because i think there is nothing wrong in my code. can you figure this out ?
You either need to await it
public async void GetDataCache(object sender, EventArgs e)
{
var loaded = await BlobCache.LocalMachine.GetObject<CachedUsers>("usercached");
txtemail.Text = loaded.FullName;
txtfullname.Text = loaded.FullName.ToString();
}
or subscribe to the IObservable
:
public async void GetDataCache(object sender, EventArgs e)
{
var loaded = await BlobCache.LocalMachine.GetObject<CachedUsers>("usercached").Subscribe(user => {
// TODO might need to wrap this in a Device.BeginInvokeOnMainThread
txtemail.Text = user.FullName;
txtfullname.Text = user.FullName.ToString();
});
}
Look into the concepts of async/await and the IObservable
object to get a better understanding of the concepts and what the problem is in this specific case.