如何确保在将数据写入高速缓存时没有人从Ehcache对象读取? [英] How to make sure that no one reads from Ehcache Object, while data is being written into the cache?

查看:226
本文介绍了如何确保在将数据写入高速缓存时没有人从Ehcache对象读取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 EhCache 将数据存储到缓存中,但是如果我尝试在将数据填充到缓存中之前访问数据,则会出现 NULL POINTER异常 .如何确保直到(除非已将数据存储到缓存中)才从缓存中读取数据?

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.

但是,使用 cache-through 可能是解决此问题的更好方法.

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.

这篇关于如何确保在将数据写入高速缓存时没有人从Ehcache对象读取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆