Defining Idempotence

前端 未结 4 1862
天命终不由人
天命终不由人 2021-01-02 04:28

So \"idempotence\" can be defined as:

An action, that if performed N times has the same effect as performing the action only once.

Got it, easy enough.

4条回答
  •  独厮守ぢ
    2021-01-02 05:04

    Suppose I have a PUT method that updates some resource, we'll call it f(x)

    Obviously, f(3) is idempotent, as long as I supply 3 as the input. And equally obvious, f(5) will change the value of the resource (i.e., it will no longer be 3 or whatever value was there previously).

    This is only obvious is the server implementation is such that PUT respects this idempotent property. In the context of HTTP, RFC 2616 says:

    Methods can also have the property of "idempotence" in that (aside from error or expiration issues) the side-effects of N > 0 identical requests is the same as for a single request.

    Going a bit off topic... In a distributed system like the web, you may also want to consider commutativity and concurrent requests. For example N+1 of the same PUT(x1) request should have the same effect, but you don't know if another client made a different PUT(x2) request in between yours, so while nPUT(x1)=PUT(x1) and mPUT(x2)=PUT(x2), the two sets of requests could be interleaved.

提交回复
热议问题