JAL-2484 added improvement to enable clearing cache items and configuring maximum...
[jalview.git] / src / jalview / io / cache / AppCache.java
index 9f9a25b..8ed33e6 100644 (file)
@@ -20,6 +20,10 @@ public class AppCache
 
   private Hashtable<String, LinkedHashSet<String>> cacheItems;
 
+  private static final String DEFAULT_LIMIT_KEY = ".DEFAULT_LIMIT";
+
+  private static final String DEFAULT_LIMIT = "99";
+
   private static final String CACHE_DELIMITER = ";";
 
   private AppCache()
@@ -115,6 +119,25 @@ public class AppCache
     persistCache(cacheKey);
   }
 
+  public String getCacheLmit(String cacheKey)
+  {
+    String uniqueKey = cacheKey + DEFAULT_LIMIT_KEY;
+    return Cache.getDefault(uniqueKey, DEFAULT_LIMIT);
+  }
+
+  public int updateCacheLimit(String cacheKey, String newLimit)
+  {
+    String uniqueKey = cacheKey + DEFAULT_LIMIT_KEY;
+    String formerLimit = getCacheLmit(cacheKey);
+    if (newLimit != null && !newLimit.isEmpty()
+            && !formerLimit.equals(newLimit))
+    {
+      Cache.setProperty(uniqueKey, newLimit);
+      formerLimit = newLimit;
+    }
+    return Integer.valueOf(formerLimit);
+  }
+
   /**
    * Method for inserting cache items for given cache key into the cache data
    * structure