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

好久不见. 提交于 2019-12-24 09:48:34

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/45490306/how-to-make-sure-that-no-one-reads-from-ehcache-object-while-data-is-being-writ

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!