1

I am trying to create a cache using Google LoadingCache.

My program uses another rest service. I am wondering if it's possible to configure the cache such that once the .refreshAfterWrite ends it calls the loadAll function.

Essentially I'd like to do something like what appears on number 8 in this link once the refreshAfterWrite timer ends. http://www.baeldung.com/guava-cache

Thanks

  • Do you want to refresh _other keys_ after one key expires? – Louis Wasserman Aug 03 '16 at 00:06
  • 1
    (It calls [`reload`](https://google.github.io/guava/releases/19.0/api/docs/com/google/common/cache/CacheLoader.html#reload(K,%20V)).) – Louis Wasserman Aug 03 '16 at 00:09
  • It sounds like you're expecting `refreshAfterWrite` to have a timer thread and you want to reload the entire cache. It doesn't work that way and you should use your own timer thread. See [docs](https://github.com/google/guava/wiki/CachesExplained#refresh) for details. – Ben Manes Aug 03 '16 at 02:02
  • @LouisWasserman I was hoping to refresh all keys at once since the API I can use brings all of the data at once since they all have to update at the same time but based on Ben's response I don't think this is possible. – Mitziu Echeverria Aug 04 '16 at 02:21

1 Answers1

1

There is no "refreshAfterWrite timer", nor any other background cleanup work being managed by the Cache - as the docs say:

refreshAfterWrite will make a key eligible for refresh after the specified duration, but a refresh will only be actually initiated when the entry is queried.

If you want to invoke loadAll() after a certain period of time you should schedule a task to do so.

dimo414
  • 47,227
  • 18
  • 148
  • 244