简体   繁体   English

Cookie与MySQL保存

[英]Cookie vs MySQL Save

I guess this is more of just a personal preference questions, but I'm really concerned with performance. 我想这更多是个人喜好问题,但我真的很关心表现。 I'm working on a little project and one thing that people can do is RSVP to events. 我正在做一个小项目,人们可以做的一件事就是对事件进行回复。 Now I know the option that people choose (attend or not attend) must be stored in a database, but to make the site look a little better, I also want the button that allows someone to attend switch to not attend when they click it. 现在,我知道人们选择(参加或不参加)的选项必须存储在数据库中,但是为了使站点看起来更好一点,我还希望允许某人参加的按钮切换为在他们单击时不参加。

At this point I'm thinking of three options, either query the database, figure out if the person is attending, and display the appropriate button. 此时,我正在考虑三个选项,要么查询数据库,确定该人是否正在参加会议,然后显示适当的按钮。 -OR- I could save the information in a cookie and just pray that the user doesn't delete the information. -或者-我可以将信息保存在cookie中,然后祈祷用户不要删除信息。 -OR- I could save the information in a cookie, if the cookie is present then display whatever the cookies says, if not then query the database. -或者-我可以将信息保存在cookie中,如果存在cookie,则显示cookie所说的内容,如果不存在,则查询数据库。 Option 3 seems the best to me. 选项3对我来说似乎是最好的。

I always kind of inspect major sites and look at some of the techniques they use. 我总是会检查主要站点,并查看它们使用的一些技术。 They tend to keep the cookie count under 20. Is there anything bad about option 3, or is it the way I should go. 他们倾向于将cookie计数保持在20以下。选项3是否有不好之处,还是我应该采取的方式。 Thanks! 谢谢!

Store it in the db. 将其存储在数据库中。 If the user logs in on a 2nd machine and changes the status, the wrong status will show when they go back to the 1st machine. 如果用户登录第二台计算机并更改状态,则当他们返回第一台计算机时将显示错误的状态。

Without the details on how people access the site, whether they are logged in or not, it is hard to say but I would agree with you on the 3rd option - query the cookie first if there i nothing, query the database - which works as long as no two people use the same computer session. 没有关于人们如何访问该站点的详细信息,无论他们是否登录,这很难说,但是我会同意您的第三个选择-如果没有任何内容,请先查询cookie,然后查询数据库-只要没有两个人使用同一计算机会话。

Another option that may work (or not depending on your web app) is to have individualized links. 另一种可行的方法(或不取决于您的Web应用程序)是具有个性化的链接。 This can work nicely if people come to your site from email links with a url similar to this http://example.com/[eventid]/[uniquecode] 如果用户通过电子邮件链接访问您的网站,而该链接的网址类似于此http://example.com/[eventid]/[uniquecode]

If you use cookie, you can expect that there is some other person who uses the same machine, the same user account, the same browser, the same settings. 如果您使用Cookie,则可以预期会有其他人使用同一台计算机,同一用户帐户,同一浏览器,同一设置。 There can be also a person who uses different browsers. 可能还有一个使用不同浏览器的人。 There can be also two persons who share two computers. 也可以有两个人共享两台计算机。

If the users log in you can use sessions, it is cookie, of course, but you can identify the user, so he knows "it's not me". 如果用户登录可以使用会话,那么它当然是cookie,但是您可以识别用户,因此他知道“不是我”。

And about performance: if you set your cookie, it takes also time to get it and then send it, via http headers and responses. 关于性能:如果设置了cookie,则还需要时间来获取它,然后通过http标头和响应将其发送。 But the best idea would be to benchmark this. 但是最好的主意是进行基准测试。 Because of the small time to access db and for the reasons I stated before, I would use the db. 由于访问数据库的时间很短,并且由于我之前所述的原因,我将使用数据库。

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

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