From 56ce07be743144f3d9cf67b7c5e199011f334efc Mon Sep 17 00:00:00 2001 From: goat Date: Thu, 6 Feb 2020 22:23:17 +0900 Subject: [PATCH] fix: use https for xivapi, make cache concurrent --- Dalamud/XivApi.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Dalamud/XivApi.cs b/Dalamud/XivApi.cs index 9d2374281..5f06a98fd 100644 --- a/Dalamud/XivApi.cs +++ b/Dalamud/XivApi.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Net.Http; @@ -13,9 +14,9 @@ namespace Dalamud { class XivApi { - private const string URL = "http://xivapi.com/"; + private const string URL = "https://xivapi.com/"; - private static readonly Dictionary cachedResponses = new Dictionary(); + private static readonly ConcurrentDictionary cachedResponses = new ConcurrentDictionary(); public static async Task GetWorld(int world) { @@ -77,8 +78,8 @@ namespace Dalamud { Log.Verbose("XIVAPI FETCH: {0}", endpoint); - if (cachedResponses.ContainsKey(endpoint) && !noCache) - return cachedResponses[endpoint]; + if (cachedResponses.TryGetValue(endpoint, out var val) && !noCache) + return val; var client = new HttpClient(); var response = await client.GetAsync(URL + endpoint); @@ -87,7 +88,7 @@ namespace Dalamud var obj = JObject.Parse(result); if (!noCache) - cachedResponses.Add(endpoint, obj); + cachedResponses.TryAdd(endpoint, obj); return obj; }