jhalterman / expiringmap

A high performance thread-safe map that expires entries
Apache License 2.0
1.01k stars 142 forks source link

Put the same key with different ttl #76

Open zysaaa opened 2 years ago

zysaaa commented 2 years ago
        expiringMap.put("a", "a", 1000, TimeUnit.MILLISECONDS);
        expiringMap.put("a", "a", 20_000, TimeUnit.MILLISECONDS);
        Thread.sleep(5000);
        System.out.println(expiringMap.get("a")); // output null

Is this expected behavior? Can't I refresh ttl of this key?

littleQiu22 commented 2 years ago

Try this:

expiringMap.put("a", "a", 1000, TimeUnit.MILLISECONDS);
expiringMap.setExpiration("a", 20_000, TimeUnit.MILLISECONDS);
Thread.sleep(5000);
System.out.println(expiringMap.get("a")); // output "a"
bratkartoffel commented 1 year ago

I think this should at least be documented on the put(K, V, long, TimeUnit) as it's kind of unexpected behaviour. Just stumbled across this issue while trying to update an entry during an ExpirationListener.