The design pattern you are referring to here is a cache
.
If the data is relatively static, you can cache the database response in some way, perhaps in a Map
with some sort of key built from the parameters of the request and perhaps with some expiration based on time (e.g. 1 hour or 1 day).
A Singleton
is indeed an implementation of a sharable object, such as the cache that you need. Note that the other answer that you refer to talks about thread safety. This can be especially important in (for example) a web service environment where threads can be used per-session or per-request.
Note that Singletons are regarded by many as being bad programming practise, not least since they are hard to test.
So another way to implement the cache would be via a singleton thread-safe cache bean
, and "wire" it in to all places that it needs to be used via dependency injection.
PS. Guava libraries have a cache builder that can be configured withe time-based expiration poilicies.
PPS. if you want to cache across multiple servers you could consider a grid solution like hazelcast
.