aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/cgeo/geocaching/Cache.java24
-rw-r--r--main/src/cgeo/geocaching/CacheCache.java7
-rw-r--r--main/src/cgeo/geocaching/gcvote/GCVote.java14
3 files changed, 30 insertions, 15 deletions
diff --git a/main/src/cgeo/geocaching/Cache.java b/main/src/cgeo/geocaching/Cache.java
new file mode 100644
index 0000000..fd94d1f
--- /dev/null
+++ b/main/src/cgeo/geocaching/Cache.java
@@ -0,0 +1,24 @@
+package cgeo.geocaching;
+
+import java.util.LinkedHashMap;
+
+/**
+ * Base class for a caching cache. Don't mix up with a geocache !
+ *
+ * @author blafoo
+ */
+public class Cache<K, V> extends LinkedHashMap<K, V> {
+
+ private static final long serialVersionUID = -5077882607489806620L;
+ private final int maxEntries;
+
+ public Cache(int maxEntries) {
+ this.maxEntries = maxEntries;
+ }
+
+ @Override
+ protected boolean removeEldestEntry(java.util.Map.Entry<K, V> eldest) {
+ return size() > maxEntries;
+ }
+
+}
diff --git a/main/src/cgeo/geocaching/CacheCache.java b/main/src/cgeo/geocaching/CacheCache.java
index ea8d749..70b4c42 100644
--- a/main/src/cgeo/geocaching/CacheCache.java
+++ b/main/src/cgeo/geocaching/CacheCache.java
@@ -3,9 +3,7 @@ package cgeo.geocaching;
import cgeo.geocaching.cgData.StorageLocation;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
/**
* Cache for Caches. Every cache is stored in memory while c:geo is active to
@@ -15,12 +13,13 @@ import java.util.Map;
*/
public class CacheCache {
- final private Map<String, cgCache> cachesCache; // caching caches into memory
+ private static final int MAX_CACHED_CACHES = 1000;
+ final private Cache<String, cgCache> cachesCache;
private static CacheCache instance = null;
private CacheCache() {
- cachesCache = new HashMap<String, cgCache>();
+ cachesCache = new Cache<String, cgCache>(MAX_CACHED_CACHES);
}
public static CacheCache getInstance() {
diff --git a/main/src/cgeo/geocaching/gcvote/GCVote.java b/main/src/cgeo/geocaching/gcvote/GCVote.java
index d0517f3..0d7f202 100644
--- a/main/src/cgeo/geocaching/gcvote/GCVote.java
+++ b/main/src/cgeo/geocaching/gcvote/GCVote.java
@@ -1,5 +1,6 @@
package cgeo.geocaching.gcvote;
+import cgeo.geocaching.Cache;
import cgeo.geocaching.Parameters;
import cgeo.geocaching.Settings;
import cgeo.geocaching.cgBase;
@@ -12,7 +13,6 @@ 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;
@@ -27,16 +27,8 @@ 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 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();
+ private static final int MAX_CACHED_RATINGS = 1000;
+ private static Cache<String, GCVoteRating> ratingsCache = new Cache<String, GCVoteRating>(MAX_CACHED_RATINGS);
/**
* Get user rating for a given guid or geocode. For a guid first the ratings cache is checked