Reputation: 251
I create cache for manual storing values:
private Cache<Long, SmsData> codeCache = Caffeine.newBuilder()
.expireAfterWrite(24, TimeUnit.HOURS)
.weakKeys()
.weakValues()
.build();
In public method after some calcultion I try to store value:
SmsData data = SopdSmsData();
data.setSendCount(++currentSendCount);
data.setCheckCount(0);
codeCache.put(id, data);
After that I want to get value, but its null:
SmsData data = codeCache.getIfPresent(id);
What I missed? Thanks in advance.
Upvotes: 0
Views: 856
Reputation: 251
I solve it next way: make field static final
and remove weakKeya(), weakValues()
Upvotes: 0