Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 public static async Task AddItemsAsync <T>(string key, CachedContent <T> data)
 {
     await AddItemsAsync <T>(key, data, true);
 }