runelite-client: cache negative item price queries

Also don't return null to guava cache, it doesn't support it
This commit is contained in:
Adam
2017-06-13 20:29:15 -04:00
parent 91c7dde12d
commit c3b3a761b4

View File

@@ -70,18 +70,24 @@ public class ItemManager
{ {
try try
{ {
return client.lookupItemPrice(key); ItemPrice itemPrice = client.lookupItemPrice(key);
if (itemPrice == null)
{
return NONE;
}
return itemPrice;
} }
catch (IOException ex) catch (IOException ex)
{ {
logger.warn("unable to look up item!", ex); logger.warn("unable to look up item!", ex);
return null; return NONE;
} }
} }
}; };
private final LoadingCache<Integer, ItemPrice> itemPrices; private final LoadingCache<Integer, ItemPrice> itemPrices;
private static final ItemPrice EMPTY = new ItemPrice(); private static final ItemPrice EMPTY = new ItemPrice();
private static final ItemPrice NONE = new ItemPrice();
public ItemManager(RuneLite runelite) public ItemManager(RuneLite runelite)
{ {
@@ -97,6 +103,11 @@ public class ItemManager
ItemPrice itemPrice = itemPrices.getIfPresent(itemId); ItemPrice itemPrice = itemPrices.getIfPresent(itemId);
if (itemPrice != null && itemPrice != EMPTY) if (itemPrice != null && itemPrice != EMPTY)
{ {
if (itemPrice == NONE)
{
return null;
}
return itemPrice; return itemPrice;
} }