放置和幂等

编程入门 行业动态 更新时间:2024-10-28 20:21:43
本文介绍了放置和幂等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

如果您的模型包含一个名为created"和updated"的字段

If you model contains a filed which are called "created" and "updated"

当您使用 PUT 更新此记录的内容时..

When you use PUT to update content to this record..

created 应该设置为数据创建或修改的时间吗?由于PUT是幂等的,所以不应该依赖之前的值

Should created be set to the time of data creation or modification? Since PUT is idempotent, so it should not rely on previous value

因为updated总是在你发出请求的时候被修改,所以违反了幂等原则?

Since updated is always modified when you issue the request, so it violated the principle of idempotent?

推荐答案

created 应该设置为数据创建或修改的时间吗?由于 PUT 是幂等的,因此不应依赖先前的值.

Should created be set to the time of data creation or modification? Since PUT is idempotent, so it should not rely on previous value.

我真的不明白你在这里问什么.没有理由将 created_at 设置为修改时间,因为它们是两个不同的概念.

I don't really understand what you're asking here. There's no reason created_at would be set to the modification time, since they are two distinct concepts.

因为updated总是在你发出请求的时候被修改,所以违反了幂等原则?

Since updated is always modified when you issue the request, so it violated the principle of idempotent?

您关于 updated_at 总是被修改的假设是不正确的(至少在 Rails 中不是,也不应该在其他任何地方).如果多次执行相同的 PUT,则不会违反幂等性,因为这些后续请求不会修改任何属性,因此 updated_at 时间 not 改变了.

Your assumption that updated_at is always modified isn't true (at least not in Rails, nor should it be anywhere else). If you do an identical PUT multiple times, idempotence is not violated since these subsequent requests don't modify any of the attributes, and thus the updated_at time is not changed.

有一个有趣的在 Rails 博客上发表关于 PUT &PATCH 增加了很多.在我看来,用户永远不应该将 created_atupdated_at 与他们的请求一起发送(因为服务器通常应该忽略它们并自行设置它们),尽管它确实是如果这违反了 PUT 应该发送整个对象的想法,这是值得怀疑的.然而,如果这个想法被忽略了(就像在 Rails 中一样,也可能在其他地方),那么 PUT 确实是幂等的.

There is an interesting post on the Rails blog about PUT & PATCH that adds a lot more to this. The way I see it, the user should never send created_at or updated_at with their request (since the server should probably usually ignore them and set them itself), though it is indeed questionable if this violates the idea that a PUT should send the entire object. However, if that idea is ignored (as it often is in Rails, and perhaps elsewhere), then PUT is indeed idempotent.

这篇关于放置和幂等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-18 06:24:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/932644.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!