aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2012-01-12 09:00:54 +0100
committerBananeweizen <bananeweizen@gmx.de>2012-01-12 09:00:54 +0100
commit1b1296da6f86459286110ce18f27f0f03e34d931 (patch)
treece13b41b19ffa9d3a636c5ce5307936754969f33 /main/src
parent8a21940bb8b201b7d8f73d99081642cf0dd5e2e1 (diff)
downloadcgeo-1b1296da6f86459286110ce18f27f0f03e34d931.zip
cgeo-1b1296da6f86459286110ce18f27f0f03e34d931.tar.gz
cgeo-1b1296da6f86459286110ce18f27f0f03e34d931.tar.bz2
change implementation of #939: hard limit for cached ratings
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/gcvote/GCVote.java14
1 files changed, 12 insertions, 2 deletions
diff --git a/main/src/cgeo/geocaching/gcvote/GCVote.java b/main/src/cgeo/geocaching/gcvote/GCVote.java
index fede9df..d0517f3 100644
--- a/main/src/cgeo/geocaching/gcvote/GCVote.java
+++ b/main/src/cgeo/geocaching/gcvote/GCVote.java
@@ -12,6 +12,7 @@ import android.util.Log;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -26,12 +27,21 @@ public final class GCVote {
private static final Pattern patternVote = Pattern.compile("voteUser='([0-9.]+)'", Pattern.CASE_INSENSITIVE);
private static final Pattern patternVoteElement = Pattern.compile("<vote ([^>]+)>", Pattern.CASE_INSENSITIVE);
- private static Map<String, GCVoteRating> ratingsCache = new HashMap<String, GCVoteRating>(); // key = guid
+ private static class RatingsCache extends LinkedHashMap<String, GCVoteRating> {
+ private static final int MAX_CACHED_RATINGS = 1000;
+
+ @Override
+ protected boolean removeEldestEntry(java.util.Map.Entry<String, GCVoteRating> eldest) {
+ return size() > MAX_CACHED_RATINGS;
+ }
+ }
+
+ private static Map<String, GCVoteRating> ratingsCache = new RatingsCache();
/**
* Get user rating for a given guid or geocode. For a guid first the ratings cache is checked
* before a request to gcvote.com is made.
- *
+ *
* @param guid
* @param geocode
* @return