Changeset 15868 in josm


Ignore:
Timestamp:
2020-02-16T23:13:25+01:00 (4 years ago)
Author:
Don-vip
Message:

see #18440 - cache API keys in memory

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/imagery/ApiKeyProvider.java

    r15855 r15868  
    66import java.net.URL;
    77import java.util.Collections;
     8import java.util.HashMap;
    89import java.util.List;
     10import java.util.Map;
    911
    1012import org.openstreetmap.josm.data.Preferences;
     
    1921 */
    2022public final class ApiKeyProvider {
     23
     24    private static final Map<String, String> CACHE = new HashMap<>();
    2125
    2226    private ApiKeyProvider() {
     
    3640     */
    3741    public static String retrieveApiKey(String imageryId) throws IOException {
     42        if (CACHE.containsKey(imageryId)) {
     43            return CACHE.get(imageryId);
     44        }
    3845        for (String siteUrl : getApiKeySites()) {
    3946            Response response = HttpClient.create(new URL(siteUrl + imageryId)).connect();
    4047            try {
    4148                if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
    42                     return Utils.strip(response.fetchContent());
     49                    String key = Utils.strip(response.fetchContent());
     50                    CACHE.put(imageryId, key);
     51                    return key;
    4352                }
    4453            } finally {
Note: See TracChangeset for help on using the changeset viewer.