X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fio%2Fcache%2FAppCache.java;h=091d30ec5b6fba202c98b20b3f11d3762495a118;hb=2d3be0b3f26fa3e35480976cd5a90a5562d43dcf;hp=8ed33e692ca1a2839165573b52280c93ebbb239c;hpb=53e3890428beabca3cdb44b90ad8e1c294d58768;p=jalview.git diff --git a/src/jalview/io/cache/AppCache.java b/src/jalview/io/cache/AppCache.java index 8ed33e6..091d30e 100644 --- a/src/jalview/io/cache/AppCache.java +++ b/src/jalview/io/cache/AppCache.java @@ -3,10 +3,8 @@ package jalview.io.cache; import jalview.bin.Cache; -import java.util.Arrays; import java.util.Hashtable; import java.util.LinkedHashSet; -import java.util.List; /** * A singleton class used for querying and persisting cache items. @@ -16,15 +14,17 @@ import java.util.List; */ public class AppCache { - private static AppCache instance = null; + public static final String DEFAULT_LIMIT = "99"; - private Hashtable> cacheItems; + public static final String CACHE_DELIMITER = ";"; + + private static AppCache instance = null; private static final String DEFAULT_LIMIT_KEY = ".DEFAULT_LIMIT"; - private static final String DEFAULT_LIMIT = "99"; - private static final String CACHE_DELIMITER = ";"; + + private Hashtable> cacheItems; private AppCache() { @@ -50,7 +50,7 @@ public class AppCache /** - * Returns an singleton instance of AppCache + * Returns a singleton instance of AppCache * * @return */ @@ -63,33 +63,7 @@ public class AppCache return instance; } - /** - * Method for initialising cache items for a given cache key - * - * @param cacheKey - */ - public void initCache(String cacheKey) - { - String separatedStr = Cache.getProperty(cacheKey); - if (separatedStr == null || separatedStr.isEmpty()) - { - return; - } - - List persistedCacheItems = Arrays.asList(separatedStr.split(CACHE_DELIMITER)); - - LinkedHashSet foundCacheItems = cacheItems.get(cacheKey); - if (foundCacheItems == null) - { - foundCacheItems = new LinkedHashSet(); - } - for (String cacheItem : persistedCacheItems) - { - foundCacheItems.add(cacheItem); - } - cacheItems.put(cacheKey, foundCacheItems); - } /** * Method for persisting cache items for a given cache key @@ -113,22 +87,46 @@ public class AppCache Cache.setProperty(cacheKey, delimitedCacheString); } + /** + * Method for deleting cached items for a given cache key + * + * @param cacheKey + * the cache key + */ public void deleteCacheItems(String cacheKey) { cacheItems.put(cacheKey, new LinkedHashSet()); persistCache(cacheKey); } - public String getCacheLmit(String cacheKey) + /** + * Method for obtaining the preset maximum cache limit for a given cache key + * + * @param cacheKey + * the cache key + * @return the max number of items that could be cached + */ + public String getCacheLimit(String cacheKey) { String uniqueKey = cacheKey + DEFAULT_LIMIT_KEY; return Cache.getDefault(uniqueKey, DEFAULT_LIMIT); } - public int updateCacheLimit(String cacheKey, String newLimit) + /** + * Method for updating the preset maximum cache limit for a given cache key + * + * @param cacheKey + * the cache key + * @param newLimit + * the max number of items that could be cached for the given cache + * key + * @return + */ + public int updateCacheLimit(String cacheKey, int newUserLimit) { + String newLimit = String.valueOf(newUserLimit); String uniqueKey = cacheKey + DEFAULT_LIMIT_KEY; - String formerLimit = getCacheLmit(cacheKey); + String formerLimit = getCacheLimit(cacheKey); if (newLimit != null && !newLimit.isEmpty() && !formerLimit.equals(newLimit)) { @@ -143,20 +141,13 @@ public class AppCache * structure * * @param cacheKey + * the cache key * @param cacheItems + * the items to add to the cache */ - public void putCache(String cacheKey, LinkedHashSet cacheItems) + public void putCache(String cacheKey, LinkedHashSet newCacheItems) { - getCacheItems().put(cacheKey, cacheItems); + cacheItems.put(cacheKey, newCacheItems); } - /** - * Getter method for obtaining cache data structure - * - * @return - */ - private Hashtable> getCacheItems() - { - return cacheItems; - } }