Using Hazelcast 5.0.2 I have a distributed map with near cache configured (no map store), if I put an entry in the distributed map with a TTL the entry is correctly removed from the distributed map when the TTL expires but it is not removed from the near cache. Is this the intended behavior?
It seems to me a bit inconsistent because the near cache is caching data which does not exist anymore, the distributed map should be the master copy and the near cache just a replica.
Thanks Riccardo
Below a code snippet to describe the expected behavior; after the ttl expires, there are no entries in the distributed map, however the entry can still be retrieved.
// add map entry
String key = "key1";
TestValue value = new TestValue("value1");
map.put(key, value, ENTRY_TTL, TimeUnit.SECONDS);
// get map entry in the near cache
TestValue retrievedValue = map.get(key);
Assertions.assertNotNull(retrievedValue);
// wait enough for the entry to be evicted in the distributed map
Sleep.waitFor(ENTRY_TTL * 2 * 1000);
long count = map.getLocalMapStats().getOwnedEntryCount();
Assertions.assertEquals(0, count);
// the map entry is returned from the near cache
retrievedValue = map.get(key);
Assertions.assertNull(retrievedValue);
Your analysis is correct, the near-cache entry is not invalidated when the primary copy is invalidated.
I would also agree the behaviour is incorrect, though it's quite subtle.
get(K)
by this process would never trigger a load(K)
get(K)
doesn't have eventual consistency of returning null.As an interim, you could use .setTimeToLiveSeconds
on the near-cache itself, though it's not exactly equivalent since the same TTL applies to all near-cache entries.
Could you log an issue for correction here please ?