feed: use caching okhttp client
This commit is contained in:
@@ -28,8 +28,10 @@ import com.google.gson.JsonParseException;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import javax.inject.Inject;
|
||||||
import net.runelite.http.api.RuneLiteAPI;
|
import net.runelite.http.api.RuneLiteAPI;
|
||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -39,6 +41,14 @@ public class FeedClient
|
|||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(FeedClient.class);
|
private static final Logger logger = LoggerFactory.getLogger(FeedClient.class);
|
||||||
|
|
||||||
|
private final OkHttpClient client;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public FeedClient(OkHttpClient client)
|
||||||
|
{
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
public FeedResult lookupFeed() throws IOException
|
public FeedResult lookupFeed() throws IOException
|
||||||
{
|
{
|
||||||
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
|
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
|
||||||
@@ -51,7 +61,7 @@ public class FeedClient
|
|||||||
.url(url)
|
.url(url)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
|
try (Response response = client.newCall(request).execute())
|
||||||
{
|
{
|
||||||
if (!response.isSuccessful())
|
if (!response.isSuccessful())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -64,10 +64,12 @@ public class FeedPlugin extends Plugin
|
|||||||
@Inject
|
@Inject
|
||||||
private ScheduledExecutorService executorService;
|
private ScheduledExecutorService executorService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private FeedClient feedClient;
|
||||||
|
|
||||||
private FeedPanel feedPanel;
|
private FeedPanel feedPanel;
|
||||||
private NavigationButton navButton;
|
private NavigationButton navButton;
|
||||||
|
|
||||||
private FeedClient feedClient = new FeedClient();
|
|
||||||
private Supplier<FeedResult> feedSupplier = Suppliers.memoizeWithExpiration(() ->
|
private Supplier<FeedResult> feedSupplier = Suppliers.memoizeWithExpiration(() ->
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
Reference in New Issue
Block a user