コード例 #1
0
ファイル: AppCache.cs プロジェクト: tuenti/waslibs
        public static async Task <CachedContent <T> > GetItemsAsync <T>(string key)
        {
            string json = null;

            if (_memoryCache.ContainsKey(key))
            {
                json = _memoryCache[key];
            }
            else
            {
                json = await UserStorage.ReadTextFromFile(key);

                _memoryCache[key] = json;
            }
            if (!String.IsNullOrEmpty(json))
            {
                try
                {
                    CachedContent <T> records = JsonConvert.DeserializeObject <CachedContent <T> >(json);
                    return(records);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }
            return(null);
        }
コード例 #2
0
ファイル: AppCache.cs プロジェクト: tuenti/waslibs
        public static async Task AddItemsAsync <T>(string key, CachedContent <T> data, bool useStorageCache)
        {
            try
            {
                string json = JsonConvert.SerializeObject(data);

                if (useStorageCache)
                {
                    await UserStorage.WriteText(key, json);
                }

                if (_memoryCache.ContainsKey(key))
                {
                    _memoryCache[key] = json;
                }
                else
                {
                    _memoryCache.Add(key, json);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
コード例 #3
0
ファイル: AppCache.cs プロジェクト: tuenti/waslibs
 private static bool DataNeedToBeUpdated <T>(CachedContent <T> dataInCache, TimeSpan expiration)
 {
     return(dataInCache == null || (DateTime.Now - dataInCache.Timestamp > expiration));
 }
コード例 #4
0
ファイル: AppCache.cs プロジェクト: tuenti/waslibs
 public static async Task AddItemsAsync <T>(string key, CachedContent <T> data)
 {
     await AddItemsAsync <T>(key, data, true);
 }