timasmith@hotmail.com schrieb:
> I have a fat client application which looks up fairly static reference
> data (database table)
[quoted text clipped - 6 lines]
> However it looks fragile and relies on the developer not making a
> mistake when assigning the key for the cached service call
I don't know what you mean. You always need a compact key for cache lookup.
There are several ways to implement memory caches in java. A more
advanced on might use weak references to use as much as possible (but
not more).
> Is there a design pattern best suited for this common issue?
>
[quoted text clipped - 12 lines]
> }
> }
You never remove data from the cache?
The LinkedHashMap has a nice feature: It can remove its eldest entry:
class MemCache extends LinkedHashMap<String, byte[]> {
private int e;
public MemCache(int entries) {
super(entries, 0.75f, true);
e = entries;
}
@Override
protected boolean removeEldestEntry(Entry<Object, byte[]> arg0) {
return size() > e;
}
}
Timo