java - How to let missing entries expire more quickly in Guava -


i have java service translates string key long id, through database lookup. i'm wrapping in guava cache reduce database queries. mapping key id doesn't change once it's set, can use long expire time existing keys. there timing issue (not in guava in app) might lookup id key before in database. not want cache "missing" mapping long. want cache though, avoid rush of queries same missing key.

i read question: handle null value ..., , there cobbled solution 2 caches. have "missing keys" cache, let expire more , has no auto-load function. check cache first, , if find there know it's missing key. otherwise, try "real" cache, catching executionexception indicate "missing" , manually populate "missing keys" cache. feels quite awkward, part throw exception in load method when there's no mapping. wonder if there isn't more elegant way handle kind of problem.

you might try based on refresh, implement cacheloader.reload(key, oldvalue) refresh "missing" mapping aggressively , keep oldvalue if oldvalue isn't "missing."


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -