简体   繁体   English

将原始数据存储在Cookie中-好主意还是坏主意?

[英]Store raw data in cookies - good idea or a bad idea?

I want to store a list of recently viewed profiles in a cookie. 我想将最近查看的配置文件列表存储在Cookie中。
I have a site where people enter game character id (World of Warcraft) and can view the character's profile. 我有一个网站,人们可以在其中输入游戏角色ID(魔兽世界),并且可以查看角色的个人资料。
Character identity consists of name (unicode, up to 15 characters), server name (unicode, up to 25 characters), and zone (2 characters, latin-1). 字符标识由名称(unicode,最多15个字符),服务器名称(unicode,最多25个字符)和区域(2个字符,latin-1)组成。
I store up to 5 recently viewed characters in cookies, URL-encoding the values, since not all browsers are unicode-cookie friendly. 我在cookie中最多存储5个最近浏览过的字符,并对值进行URL编码,因为并非所有浏览器都支持unicode cookie。

This makes this cookie up two 500 characters long. 这使该Cookie的长度达到了两个500个字符。

Question: is this a reasonable approach? 问题:这是合理的方法吗? Here are few other solutions I would like you to evaluate. 这是我希望您评估的其他一些解决方案。

  1. Store characterId as it is defined in the database. 存储在数据库中定义的characterId。 Pros: small cookie size, Cons: a) character can be removed from the database (database is just a cache to speed up update), b) database can get re-indexed. 优点:cookie大小小,缺点:a)可以从数据库中删除字符(数据库只是用于加快更新速度的缓存),b)数据库可以重新索引。
  2. store name+server+zone hash, and look it up by hash in database. 存储名称+服务器+区域哈希,并在数据库中按哈希查找它。 Cons: a) again, character can be removed from the database, Pros: reindexing resistant. 缺点:a)同样,可以从数据库中删除字符,优点:耐重新索引编制。
  3. require a user to create an account and store it there. 要求用户创建一个帐户并将其存储在该帐户中。 Cons: nobody likes creating accounts, and I rather not do this. 缺点:没有人喜欢创建帐户,我宁愿不这样做。

Am I splitting hairs and my present solution (store URL-encoded list in a cookie) is good enough? 我是否可以拆分头发并且我目前的解决方案(将URL编码的列表存储在cookie中)足够好?

EDIT: It is important to note that "recent characters" list is there just for convenience, if it gets cleared - it is not a problem at all (it's akin to a 'recent files' in some applications). 编辑:重要的是要注意,“最近字符”列表只是为了方便起见,如果它被清除的话-根本不是问题(类似于某些应用程序中的“最近文件”)。

Personally, I would prefer to have the ID stored in the cookie and have the rest of the data in the database. 就个人而言,我希望将ID存储在cookie中,并将其余数据存储在数据库中。 If the data can be deleted during a user's session, create a new table just for the user's session (use their session_id) and have that ID stored in the cookie. 如果可以在用户会话期间删除数据,请为该用户会话创建一个新表(使用其session_id),并将 ID存储在cookie中。 Put a datetime in that table and periodically (like in a cron job) delete any records that are older than x days. 将日期时间放在该表中,并定期(如在cron作业中)删除所有早于x天的记录。

If you are not experiencing problems (or limitations) with your current solution, I would keep it as is. 如果您当前的解决方案没有遇到问题(或限制),我将保持原样。 Be aware, by storing the entire character, and presenting that data, the data could be outdated. 请注意,通过存储整个字符并显示该数据,数据可能已过时。

I would store the ID's in a cookie and do some server side logic to return the available characters from the list of ID's. 我将ID存储在cookie中,并执行一些服务器端逻辑以从ID列表中返回可用字符。 ID's which are not present in the database can be skipped from displaying and turning up in the list of ID's again. 可以跳过数据库中不存在的ID,使其不再显示并再次出现在ID列表中。

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

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