java - Guava LoadingCache: Why use refreshAfterWrite and expireAfterWrite together -


i read document explaining guava cache: cachesexplained. understand refreshafterwrite , expireafterwrite doing. however, while explaining refreshafterwrite, document mentions this:

"so, example, can specify both refreshafterwrite , expireafterwrite on same cache, expiration timer on entry isn't blindly reset whenever entry becomes eligible refresh, if entry isn't queried after comes eligible refreshing, allowed expire."

this part confuses me. understanding, if want key automatically refreshed, need specify refreshafterwrite. why want use expireafterwrite when ever refreshafterwrite used?

there scenarios in you'll want cached entries relevant set refresh duration (which might lighter perform (and async), rather full fetch after eviction , hence, different), @ same time, if cache bounded, you'll want evict entries, that's expireafterwrite for. setting them both, you'll make sure entry evicted after time, if refreshed.

also note both differs in way operate:

refreshing not quite same eviction. specified in loadingcache.refresh(k), refreshing key loads new value key, possibly asynchronously. old value (if any) still returned while key being refreshed, in contrast eviction, forces retrievals wait until value loaded anew.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -