过去几天与 Akavache 合作。我有几种使用 GetAndFetchLatest 方法的方法,但有些方法从不调用 fetchFunc,并且所有函数都随机出现问题。
public async Task<ChecklistModel> GetChecklistTypes()
{
var ChecklistTypesCache =
BlobCache.LocalMachine.GetAndFetchLatest("ChecklistTypes",
() => GetChecklistTypesRemote(),
offset =>
{
TimeSpan elapsed = DateTimeOffset.Now - offset;
return elapsed > new TimeSpan(hours: 0, minutes: 5, seconds: 0);
});
ChecklistTypesCache.Subscribe(subsribedData =>
{
_checkilstModel = subsribedData;
});
_checkilstModel = await ChecklistTypesCache.FirstOrDefaultAsync();
return _checkilstModel;
}
public async Task<ChecklistModel> GetChecklistTypesRemote()
{
//do something
}
有人遇到过这个问题吗?我需要做其他事情才能工作吗?如何解决这个问题?
“更新代码”
public async Task<IEnumerable<ChecklistModel.Checklist>>
GetChecklistTypesCache()
{
IEnumerable<ChecklistModel.Checklist> checklistModel = null;
var ChecklistTypesCache =
BlobCache.LocalMachine.GetAndFetchLatest("ChecklistAccessLevels",
() => GetChecklistTypesRemote(),
offset =>
{
TimeSpan elapsed = DateTimeOffset.Now -
offset;
return elapsed > new TimeSpan(hours: 0,
minutes: 5, seconds: 0);
});
ChecklistTypesCache.Subscribe(subsribedData =>
{
checklistModel = subsribedData;
});
checklistModel = await ChecklistTypesCache.FirstOrDefaultAsync();
return checklistModel;
}
public async Task<IEnumerable<ChecklistModel.Checklist>> GetChecklistTypesRemote()
{
//do something
}