T
timasmith
I have a fat client application which looks up fairly static reference
data (database table)
Example - columns to display for a search result list
I have the following code below as a snippet to cache the results while
the application is running - restarting the app clears the cache.
However it looks fragile and relies on the developer not making a
mistake when assigning the key for the cached service call
Is there a design pattern best suited for this common issue?
private static Hashtable cache = new Hashtable();
public static AppColumnList getSearchColumns(int applicationId) {
String key = applicationId + ":ServiceClass:getSearchColumns";
if (cache.containsKey(key)) {
AppColumnList value = (AppColumnList) cache.get(key);
return value;
} else {
AppColumnList value = getService().getAppColumns(applicationId,
userid);
cache.put(key,value);
return value;
}
}
data (database table)
Example - columns to display for a search result list
I have the following code below as a snippet to cache the results while
the application is running - restarting the app clears the cache.
However it looks fragile and relies on the developer not making a
mistake when assigning the key for the cached service call
Is there a design pattern best suited for this common issue?
private static Hashtable cache = new Hashtable();
public static AppColumnList getSearchColumns(int applicationId) {
String key = applicationId + ":ServiceClass:getSearchColumns";
if (cache.containsKey(key)) {
AppColumnList value = (AppColumnList) cache.get(key);
return value;
} else {
AppColumnList value = getService().getAppColumns(applicationId,
userid);
cache.put(key,value);
return value;
}
}