简体   繁体   中英

How to make sure that no one reads from Ehcache Object, while data is being written into the cache?

I want to store data into the Cache using EhCache , but if I try to access the data before data has been populated into the Cache, I get NULL POINTER exception . How can I make sure that Data is not read from the cache until and unless data has been stored into the Cache?

What you are requesting will make cache usage very problematic.

If you always block on a missing entry, any eviction or expiry will put you in the same situation as having an empty cache / missing mapping.

However, using cache-through might be a better way to look at the problem. It would leave the loading of the mapping to the cache itself making sure you never get a null result (unless that key does not exist in the backing store).

See documentation for more information on that option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM