Skip to content

Commit

Permalink
test cache on more than just match...
Browse files Browse the repository at this point in the history
  • Loading branch information
stelar7 committed Aug 30, 2017
1 parent 10df45e commit 780b797
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public abstract class CacheProvider
*
* @param type the endpoint
*/
public abstract void clear(URLEndpoint type);
public abstract void clear(URLEndpoint type, Object... filter);

/**
* Removes any old items frcm the cache
Expand Down Expand Up @@ -109,19 +109,19 @@ public Optional<?> get(URLEndpoint type, Object... data)
}

@Override
public void clear(URLEndpoint type)
public void clear(URLEndpoint type, Object... filter)
{/*void cache*/}

@Override
public void clearOldCache()
{/*void cache*/}

@Override
public long getTimeToLive()
{
return 0;
}

@Override
public long getSize()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,18 @@ public Optional<?> get(URLEndpoint type, Object... data)
}

@Override
public void clear(URLEndpoint type)
public void clear(URLEndpoint type, Object... filter)
{
try
{
Files.walk(home.resolve(type.toString())).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
Path pathToWalk = home.resolve(type.toString());

for (Object o : filter)
{
pathToWalk = pathToWalk.resolve(o.toString());
}

Files.walk(pathToWalk).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
} catch (IOException e)
{
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ public Optional<?> get(URLEndpoint type, Object... data)
}

@Override
public void clear(URLEndpoint type)
public void clear(URLEndpoint type, Object... filter)
{
// TODO: respect filter
switch (type)
{
case V3_SUMMONER_BY_ACCOUNT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ private void restoreCache(CacheProvider stoppingPoint, URLEndpoint type, Object
}

@Override
public void clear(URLEndpoint type)
public void clear(URLEndpoint type, Object... filter)
{
providers.forEach(p -> p.clear(type));
providers.forEach(p -> p.clear(type, filter));
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/no/stelar7/api/l4j8/impl/ChampionAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public List<Champion> getChampions(Platform server, boolean freeToPlay)


ChampionList cl = (ChampionList) builder.build();
DataCall.getCacheProvider().store(URLEndpoint.V3_CHAMPIONS, cl.getChampions());
DataCall.getCacheProvider().store(URLEndpoint.V3_CHAMPIONS, cl.getChampions(), server);
return cl.getChampions();
}

Expand All @@ -58,7 +58,7 @@ public Champion getChampion(Platform server, int id)
}

Champion ch = (Champion) builder.build();
DataCall.getCacheProvider().store(URLEndpoint.V3_CHAMPIONS_BY_ID, ch);
DataCall.getCacheProvider().store(URLEndpoint.V3_CHAMPIONS_BY_ID, ch, server, id);
return ch;
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/no/stelar7/api/l4j8/impl/LeagueAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public LeagueList getMasterLeague(Platform server, GameQueueType queue)
}

LeagueList list = (LeagueList) builder.build();
DataCall.getCacheProvider().store(URLEndpoint.V3_LEAGUE_MASTER, list);
DataCall.getCacheProvider().store(URLEndpoint.V3_LEAGUE_MASTER, list, server, queue);
return list;
}

Expand Down Expand Up @@ -74,7 +74,7 @@ public LeagueList getChallengerLeague(Platform server, GameQueueType queue)
}

LeagueList list = (LeagueList) builder.build();
DataCall.getCacheProvider().store(URLEndpoint.V3_LEAGUE_CHALLENGER, list);
DataCall.getCacheProvider().store(URLEndpoint.V3_LEAGUE_CHALLENGER, list, server, queue);
return list;

}
Expand All @@ -96,14 +96,14 @@ public List<LeaguePosition> getLeaguePosition(Platform server, long summonerId)
.withEndpoint(URLEndpoint.V3_LEAGUE_ENTRY)
.withPlatform(server);

Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_LEAGUE_ENTRY, server, summonerId);
Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_LEAGUE_ENTRY, summonerId, server);
if (chl.isPresent())
{
return (List<LeaguePosition>) chl.get();
}

List<LeaguePosition> list = (List<LeaguePosition>) builder.build();
DataCall.getCacheProvider().store(URLEndpoint.V3_LEAGUE_ENTRY, list);
DataCall.getCacheProvider().store(URLEndpoint.V3_LEAGUE_ENTRY, list, summonerId, server);
return list;
}

Expand All @@ -123,14 +123,14 @@ public List<LeagueList> getLeague(Platform server, long summonerId)
.withEndpoint(URLEndpoint.V3_LEAGUE)
.withPlatform(server);

Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_LEAGUE, server, summonerId);
Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_LEAGUE, summonerId, server);
if (chl.isPresent())
{
return (List<LeagueList>) chl.get();
}

List<LeagueList> list = (List<LeagueList>) builder.build();
DataCall.getCacheProvider().store(URLEndpoint.V3_LEAGUE, list);
DataCall.getCacheProvider().store(URLEndpoint.V3_LEAGUE, list, summonerId, server);
return list;
}
}
6 changes: 3 additions & 3 deletions src/main/java/no/stelar7/api/l4j8/impl/MasteryAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Integer getMasteryScore(Platform server, long summonerId)
}

Integer list = (Integer) builder.build();
DataCall.getCacheProvider().store(URLEndpoint.V3_MASTERY_SCORE, list);
DataCall.getCacheProvider().store(URLEndpoint.V3_MASTERY_SCORE, list, server, summonerId);
return list;
}

Expand Down Expand Up @@ -119,7 +119,7 @@ public ChampionMastery getChampionMastery(Platform server, long summonerId, int
}
}

DataCall.getCacheProvider().store(URLEndpoint.V3_MASTERY_BY_CHAMPION, mastery);
DataCall.getCacheProvider().store(URLEndpoint.V3_MASTERY_BY_CHAMPION, mastery, server, summonerId, championId);
return mastery;
}

Expand All @@ -146,7 +146,7 @@ public List<ChampionMastery> getChampionMasteries(Platform server, long summoner
}

List<ChampionMastery> list = (List<ChampionMastery>) builder.build();
DataCall.getCacheProvider().store(URLEndpoint.V3_MASTERY_BY_ID, list);
DataCall.getCacheProvider().store(URLEndpoint.V3_MASTERY_BY_ID, list, server, summonerId);
return list;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/no/stelar7/api/l4j8/impl/MatchAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public Match getMatch(Platform server, long matchId)
}

Match match = (Match) builder.build();
DataCall.getCacheProvider().store(URLEndpoint.V3_MATCH, match);
DataCall.getCacheProvider().store(URLEndpoint.V3_MATCH, match, server);
return match;
}

Expand All @@ -198,7 +198,7 @@ public MatchTimeline getTimeline(Platform server, long matchId)
}

MatchTimeline timeline = (MatchTimeline) builder.build();
DataCall.getCacheProvider().store(URLEndpoint.V3_TIMELINE, timeline);
DataCall.getCacheProvider().store(URLEndpoint.V3_TIMELINE, timeline, matchId, server);
return timeline;
}
}
4 changes: 2 additions & 2 deletions src/main/java/no/stelar7/api/l4j8/impl/SpectatorAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public List<SpectatorGameInfo> getFeaturedGames(Platform server)
}

FeaturedGames fg = (FeaturedGames) builder.build();
DataCall.getCacheProvider().store(URLEndpoint.V3_SPECTATOR_FEATURED, fg.getGameList());
DataCall.getCacheProvider().store(URLEndpoint.V3_SPECTATOR_FEATURED, fg.getGameList(), server);
return fg.getGameList();

}
Expand Down Expand Up @@ -69,7 +69,7 @@ public SpectatorGameInfo getCurrentGame(Platform server, long summonerId)
}

SpectatorGameInfo fg = (SpectatorGameInfo) builder.build();
DataCall.getCacheProvider().store(URLEndpoint.V3_SPECTATOR_CURRENT, fg);
DataCall.getCacheProvider().store(URLEndpoint.V3_SPECTATOR_CURRENT, fg, server);
return fg;
}
}
2 changes: 1 addition & 1 deletion src/main/java/no/stelar7/api/l4j8/impl/StatusAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ShardStatus getShardStatus(Platform server)
}

ShardStatus list = (ShardStatus) builder.build();
DataCall.getCacheProvider().store(URLEndpoint.V3_SHARD_STATUS, list);
DataCall.getCacheProvider().store(URLEndpoint.V3_SHARD_STATUS, list, server);
return list;
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/no/stelar7/api/l4j8/impl/SummonerAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public List<MasteryPage> getMasteries(final Platform server, long summonerId)
}

MasteryPages list = (MasteryPages) builder.build();
DataCall.getCacheProvider().store(URLEndpoint.V3_MASTERIES_BY_ID, list.getPages());
DataCall.getCacheProvider().store(URLEndpoint.V3_MASTERIES_BY_ID, list.getPages(), server, summonerId);
return list.getPages();
}

Expand All @@ -72,7 +72,7 @@ public List<RunePage> getRunes(final Platform server, long summonerId)
}

RunePages list = (RunePages) builder.build();
DataCall.getCacheProvider().store(URLEndpoint.V3_RUNES_BY_ID, list.getPages());
DataCall.getCacheProvider().store(URLEndpoint.V3_RUNES_BY_ID, list.getPages(), server, summonerId);
return list.getPages();
}

Expand All @@ -98,7 +98,7 @@ public Summoner getSummonerById(final Platform server, long summonerId)
}

Summoner summoner = (Summoner) builder.build();
DataCall.getCacheProvider().store(URLEndpoint.V3_SUMMONER_BY_ID, summoner);
DataCall.getCacheProvider().store(URLEndpoint.V3_SUMMONER_BY_ID, summoner, summonerId, server);
return summoner;
}

Expand All @@ -124,7 +124,7 @@ public Summoner getSummonerByName(final Platform server, String summonerName)
}

Summoner summoner = (Summoner) builder.build();
DataCall.getCacheProvider().store(URLEndpoint.V3_SUMMONER_BY_NAME, summoner);
DataCall.getCacheProvider().store(URLEndpoint.V3_SUMMONER_BY_NAME, summoner, summonerName, server);
return summoner;
}

Expand All @@ -149,7 +149,7 @@ public Summoner getSummonerByAccount(final Platform server, long accountId)
}

Summoner summoner = (Summoner) builder.build();
DataCall.getCacheProvider().store(URLEndpoint.V3_SUMMONER_BY_ACCOUNT, summoner);
DataCall.getCacheProvider().store(URLEndpoint.V3_SUMMONER_BY_ACCOUNT, summoner, accountId, server);
return summoner;
}
}
11 changes: 11 additions & 0 deletions src/test/java/no/stelar7/api/l4j8/tests/cache/CacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ public void testStaticDataCache() throws InterruptedException
l4j8.getStaticAPI().getChampions(Platform.EUW1, null, null, null);
}

@Test
public void testCacheStuff() throws InterruptedException
{
DataCall.setLogLevel(LogLevel.DEBUG);
DataCall.setCacheProvider(new FileSystemCacheProvider());
l4j8.getSummonerAPI().getSummonerById(Constants.TEST_PLATFORM[0], Constants.TEST_SUMMONER_IDS[0]);
l4j8.getSummonerAPI().getSummonerById(Constants.TEST_PLATFORM[0], Constants.TEST_SUMMONER_IDS[0]);
l4j8.getLeagueAPI().getLeague(Constants.TEST_PLATFORM[0], Constants.TEST_SUMMONER_IDS[0]);
l4j8.getLeagueAPI().getLeague(Constants.TEST_PLATFORM[0], Constants.TEST_SUMMONER_IDS[0]);
}

@Test
public void testTieredMemoryCache() throws InterruptedException
{
Expand Down

0 comments on commit 780b797

Please sign in to comment.