changeset 306:9dbeb88006e9

Added simple in-memory LRU cache artifacts/trunk@2414 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 28 Jul 2011 14:08:25 +0000
parents f33401ea2a6c
children d96bcb40dbf9
files ChangeLog artifacts-common/src/main/java/de/intevation/artifacts/common/utils/LRUCache.java
diffstat 2 files changed, 31 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Jul 28 10:19:35 2011 +0000
+++ b/ChangeLog	Thu Jul 28 14:08:25 2011 +0000
@@ -1,3 +1,8 @@
+2011-07-28	Sascha L. Teichmann	<teichmann@intevation.de>
+
+	* artifacts-common/src/main/java/de/intevation/artifacts/common/utils/LRUCache.java:
+	  New. Simple LRU cache based on java.util.LinkedHashMap.
+
 2011-07-28	Sascha L. Teichmann	<teichmann@intevation.de>
 
 	Refactorized the usage of dialect independent SQL to be reusable.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts-common/src/main/java/de/intevation/artifacts/common/utils/LRUCache.java	Thu Jul 28 14:08:25 2011 +0000
@@ -0,0 +1,26 @@
+package de.intevation.artifacts.common.utils;
+
+import java.util.Map;
+import java.util.LinkedHashMap;
+
+public class LRUCache<K, V>
+extends      LinkedHashMap<K, V> 
+{
+    public static final int DEFAULT_MAX_CAPACITY = 25;
+
+    private int maxCapacity;
+
+    public LRUCache() {
+        this(DEFAULT_MAX_CAPACITY);
+    }
+
+    public LRUCache(int maxCapacity) {
+        this.maxCapacity = maxCapacity;
+    }
+
+    @Override
+    protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
+        return size() > maxCapacity;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org