You can check out LinkedHashMap to implement a simple cache without third party jars:
Map <String, Foo> cache = new LinkedHashMap<String, Foo>(MAX_ENTRIES + 1, .75F, true) {
public boolean removeEldestEntry(Map.Entry<String, Foo> eldest) {
return size() > MAX_ENTRIES;
}
};
then you can get from the cache like
Foo foo = cache.get(key);
if (foo == null && !cache.containsKey(key)) {
try {
FooDAO fooDAO = DAOFactory.getFooDAO(conn);
foo = fooDAO.getFooByKey(key);
cache.put(key, foo);
} catch (SQLException sqle) {
logger.error("[getFoo] SQL Exception when accessing Foo", sqle);
}
}
rest left as exercise for reader :)