简体   繁体   中英

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?

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.

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.

Cookies can only save text whereas you can practically save anything in a database as binary objects.

Any preferences saved with Cookies would only take effect if the user uses the same browser that the cookies were stored on. So, databases are also more suited for any preferences that should be mobile.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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