I'm looking to cache information in a Map so I don't have to keep, for example, hitting a DB. In Java I'd use Google collection's excellent MapMaker and set an expiry, to keep the cache as fresh as necessary, and softValues, to keep the memory usage down. Then I'd have a function that computes the value for a key that currently isn't cached.
MapMaker().softValues
.expireAfterWrite(10, TimeUnit.MINUTES)
.makeComputingMap(Function(...));
What's the best way to do this in Scala?