I'm working with the Scala version of Caffeine, Scaffeine.
I'm trying to populate a cache, in a way that it should reload all the values after expiration (10sec in the test). I probably I could use Guava's Suppliers.memoizeWithExpiration
but I'd like to take the advantage of the asynchronous loading of data in the background.
I have the following snippet:
val dummy = List()
val myCache: AsyncLoadingCache[String, String] =
Scaffeine()
.refreshAfterWrite(10.second) //test
.buildAsyncFuture(
loader = userId => client.getByUserId(userId),
allLoader = Some(dummy => client.getAllUsers),
reloadLoader = None)
I'd thought that allLoader
is for this purpose, but it's called only once during cache construction time, and only those values are populated for which the keys are enumerated in the "dummy" list.
There's a similar thread which suggests to implement CacheLoader#loadAll
but any hint would be great how to implement this
possibly in Scala with Scaffeine?