protected IObservable <T> GetDataAsync <T>(RestfullRequest <T> request, CachePolicy cachePolicy = CachePolicy.GetFromCacheAndUpdate) where T : class { if (!_cache.IsCached <T>(request.Url)) { Debug.WriteLine("DataProvider::Getting data:" + request.Url); return(Observable.Create <T>( observer => Scheduler.Default.Schedule(() => ExecuteRequest(request, observer)) )); } Debug.WriteLine("DataProvider::Getting cached data:" + request.Url); return(Observable.Create <T>( observer => Scheduler.Default.Schedule(() => { var item = _cache.Fetch <T>(request.Url); observer.OnNext(item); if (cachePolicy == CachePolicy.TryGetFromCache) { observer.OnCompleted(); } else { var updatable = item as IUpdatableModel; if (updatable != null) { CheckIfNeededToBeUpdated(request, updatable, observer); } else { Debug.WriteLine("UpdateData:" + request.Url); ExecuteRequest(request, observer, true); } } }) )); }
protected IObservable <T> GetDataAsync <T>(RestfullRequest <T> request) where T : new() { if (!_cache.IsCached <T>(request.Url)) { Debug.WriteLine("Getting data:" + request.Url); return(Observable.Create <T>( observer => Scheduler.Default.Schedule(() => ExecuteRequest(request, observer)) )); } Debug.WriteLine("Getting cached data:" + request.Url); return(Observable.Create <T>( observer => Scheduler.Default.Schedule(() => { var item = _cache.Fetch <T>(request.Url); observer.OnNext(item); Debug.WriteLine("UpdateData:" + request.Url); ExecuteRequest(request, observer, true); }) )); }