Similar to this thread, but not exactly: How To Cache Information In A Threadsafe Manner
What is the usual pattern for dealing with "reference data" - data that is frequently read by an application, usually externalized in a database or properties file, but updated very infrequently (days, weeks, months)? When the data is updated, it would be updated externally.
Would this normally be a singleton that I could inject with a DAO and would thus be able to manage its own contents? I like the idea of exposing a refresh() method on this service that would force a refresh (i.e., through an MBean - so I wouldn't have to bounce the application).
From the other SO thread, it sounds like people might just instantiate the DAO's whenever necessary and cache transparently at that level.
I kind of like the idea of the singleton service being injected with either a real DAO that loads data from the database, or else a mock/test-double that returns a hard-coded response. However, if I were to implement the service as a singleton via java enum's, this makes wiring it up via Spring a bit more problematic.
So, how do other people typically deal with reference data? Query-at-will but with caching under the covers? Or a separate in-memory service?