Exemplo n.º 1
0
        internal async Task <DataSourceContent <T> > UpdateCache()
        {
            var freshData = new DataSourceContent <T>()
            {
                TimeStamp = DateTime.Now,
                Items     = await LoadDataAsync()
            };

            await AppCache.AddItemsAsync(CacheKey, freshData);

            return(freshData);
        }
Exemplo n.º 2
0
        public async Task <DateTime> LoadDataAsync(ObservableCollection <T> viewItems, bool forceRefresh)
        {
            DateTime timeStamp = DateTime.Now;

            if (HasStaticData)
            {
                viewItems.AddRangeUnique(await LoadDataAsync());
            }
            else
            {
                var dataInCache = await AppCache.GetItemsAsync <T>(CacheKey);

                if (dataInCache != null)
                {
                    timeStamp = dataInCache.TimeStamp;

                    viewItems.AddRangeUnique(dataInCache.Items);
                }

                if (NetworkInterface.GetIsNetworkAvailable() && DataNeedToBeUpdated(forceRefresh, dataInCache))
                {
                    var freshData = new DataSourceContent <T>()
                    {
                        TimeStamp = DateTime.Now,
                        Items     = await LoadDataAsync()
                    };

                    timeStamp = freshData.TimeStamp;

                    viewItems.AddRangeUnique(freshData.Items);

                    await AppCache.AddItemsAsync(CacheKey, freshData);
                }
            }
            return(timeStamp);
        }