Closed sahil3390 closed 1 year ago
Can you show me the actual code driving the cache here? If it's just two threads doing:
if (cache.get(key) == null) {
cache.put(key, value);
}
in parallel then this is expected behavior. The two cache operations are not atomic, and both threads can see null and put independently.
Two threads access(get if not present put) the cache simultaneouly and performs get/put for element 1-10 in cache . In this case it is observed that getCachePuts() return random values. Usually it is observed that getCachePuts() comes out to be 12 or 16 in case cache size is 10. As per our understanding getCachePuts() should be 10 as elements 1-10 are being accessed. The configured time to idle is 1 hour. For example in one of the run of the unit case following were the respective values: getCachePuts= 12 getCacheRemovals= 0 getCacheEvictions= 0 getCacheExpirations= 0