stelar7 / R4J

A Java library containing the API for every Riot game
Apache License 2.0
87 stars 29 forks source link

Cache issue with Account-V1 API #95

Closed Glowning-Dev closed 6 months ago

Glowning-Dev commented 6 months ago

Since the /tft/summoner/v1/summoners/by-name/{summonerName} and /lol/summoner/v4/summoners/by-name/{summonerName} routes are deprecated and will be removed in the future, I'm updating my application by using the Account-V API.

However, for the same Riot Account, the PUUID is different for each game.

For example, two requests: the first one made with my TFT API Key and the second one with my LoL API Key, on the following endpoint https://europe.api.riotgames.com/riot/account/v1/accounts/by-riot-id/KC%20%EC%97%94%EC%A1%B0/0806

{
    "puuid": "ngKh-7nYhEi_bJdMTsm6aFXHmYa92iHqlN3tXRYFMVHCoflW9U67MWe0QBr_tepFjz0B4jmOauDP6A",
    "gameName": "KC 엔조",
    "tagLine": "0806"
}
{
    "puuid": "rr6plkANXviBdEZ_m2onwAkb7Vs5NLtUCHONe-Q2IzUGPIEsM8toQlPUEkBqauZmZBGdi21IdnrqKg",
    "gameName": "KC 엔조",
    "tagLine": "0806"
}

The problem is, that R4J cache system detects that it comes from the same URI even if a different API Key is used. The following code will only produce one cache entry.

RiotAccount lolAccount = accountAPI.getAccountByTag(RegionShard.EUROPE, name, tag, ApiKeyType.LOL);
RiotAccount tftAccount = accountAPI.getAccountByTag(RegionShard.EUROPE, name, tag, ApiKeyType.TFT);

image

Therefore, when I try to retrieve my TFT Summoner by using Summoner#getSummonerByPUUID it ends up with an error because it executes the request with my LoL PUUID.

The obvious solution would be to retrieve TFT and LoL Riot Accounts with a different RegionShard so that it is stored in two different cache location, but R4J may be enhanced by detecting what API Key we're using to store in two different folders by default?