简体   繁体   English

获取cookie值或从数据库获取数据?

[英]Getting cookie value or getting data from DB?

Which of these operations require more time and resources? 其中哪些操作需要更多时间和资源? Getting cookie value or getting data from DB? 获取cookie值或从数据库获取数据?

They both serve a different purpose. 它们都有不同的目的。 Cookies are used to store preferences and are disposable in a sense that if they aren't available (like the client deleted them) the preferences switch to defaults. Cookies用于存储首选项,并且在无法使用(例如客户端将其删除)的某种意义上是可丢弃的,首选项会切换为默认值。

Database on the other hand would store data that should persist through-out the application's life. 另一方面, 数据库将存储应在应用程序的整个生命周期中保留的数据。 For example, user login data. 例如,用户登录数据。 You can't save that as cookies for security reasons as well as that you may lose them any time. 出于安全原因,您不能将其另存为cookie,也有可能随时丢失它们。

Cookies can only save text whereas you can practically save anything in a database as binary objects. Cookies只能保存文本,而实际上您可以将数据库中的任何内容保存为二进制对象。

Any preferences saved with Cookies would only take effect if the user uses the same browser that the cookies were stored on. 使用Cookie保存的所有首选项只有在用户使用存储Cookie的浏览器时才生效。 So, databases are also more suited for any preferences that should be mobile. 因此, 数据库也更适合应移动的任何首选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM