Пример #1
0
        public static async Task <T> CacheOfByUrl <T>(Uri url) where T : ApiObject
        {
            if (!ShouldCacheData)
            {
                return(JsonConvert.DeserializeObject <T>(await Client.GetStringAsync(url.AbsoluteUri)));
            }

            var type = typeof(T);

            if (!CacheUrl.ContainsKey(type))
            {
                CacheUrl.Add(type, new Dictionary <Uri, ApiObject>());
            }

            var dictionary = CacheUrl[type];

            if (!dictionary.TryGetValue(url, out var apiObject))
            {
                apiObject = JsonConvert.DeserializeObject <T>(await Client.GetStringAsync(url.AbsoluteUri));
                dictionary.Add(url, apiObject);
            }

            return((T)apiObject);
        }
Пример #2
0
 public static void ClearAll()
 {
     Cache.Clear();
     CacheString.Clear();
     CacheUrl.Clear();
 }