First, I assume you mean remove rather than clear? Clear removes all entries in 
the cache (and takes no parameters).

With that, yes, your sequence of events could happen.

There are (at least) two alternative ways of doing it.

“Put” doesn’t “check that a value already exists.” It simply puts the value in 
the cache, regardless of whether a value exists or not. If you want to replace 
an existing value, you should use the “replace” method.

Alternatively, you could use transactions.

Regards,
Stephen

> On 28 Jan 2020, at 13:01, Narsi Reddy Nallamilli <[email protected]> 
> wrote:
> 
> Hello,
> 
> Consider I have below cache on server node
> 
> Cache
> -----------
> key,value
> ------------
> 1   | a
> ------------
> 
> From client node1, I try to do put(1,a) and from client node2 I try to do 
> clear(1). 
> 
> Are put and clear atomic, mean could this happen?
> 
> 1. cliennode1 put operation identified that key with 1 exist and it decided 
> to update the value.
> 2. clientnode2 cleared the entry from cache
> 3. clientnode1 put operation now tries to update the entry with key 1
> 
> 


Reply via email to