问题描述
什么是有关高速缓存VS会话VS饼干该做的和不该做的?
What are the do's and don'ts about Cache VS Session VS Cookies?
例如:
使用Session变量很多和Im有问题,有时在预订应用程序,当用户开始订购产品,然后去吃午饭,后来回来几个小时,并继续预订。我存储在会话预订,直到用户确认或中止预约,所以我不需要交谈的数据库和处理订单中途在数据库中,当用户只需点击浏览器中的X和永不回来。
For example:Im using Session variables a lot and have sometimes problem in a booking-application when users starts to order products and then goes to lunch and come back some hours later and continue the booking. I store the booking in the session until the user confirm or abort the booking so I dont need to talk to the database and handle halfway bookings in the database when users just click the X in the browser and never comes back.
我应该改用cashe或饼干或所有这一切之上的任意组合?
Should I instead use cashe or cookies or any combination of all above for this?
(我也有问题时,也有一些错误在应用程序中sessison对象重置本身,我得到了很多,因为有更多的问题)
(I have also had problems as when there are some error in the app the sessison-object resets itself and I got a lots of more problems because of that)
林大多是做桌面编程和觉得我缺少这里很多知识,因此任何人谁可以在哪里使用缓存,会话,饼干扩大(或DB)
Im mostly doing desktop-programming and feel I lack a lots of knowledge here so anyone who can expand on where to use Cache, Session, cookies (or db)
编辑:从答案似乎DB和饼干组合是我想要的。
From the answers it seems that a combination of DB and cookies is what I want.
- 我必须存放在连接到一个会话ID数据库预订
- 存储在cookie(加密)的会话ID。
- 每个页面加载检查Cookie,并从数据库中获取预订
- 我有扫清疲于奔命预订每周一次运行一个清理的过程。
我不能预订存储为一个cookie,因为这时用户可以更改价格和其他敏感数据,我不得不验证一切(不能信任的数据)。
I cant store the booking as a cookie because then the user can change prices and other sensitive data and I had to validate everything (cant trust the data).
有我懂了吧?
和感谢伟大的解释大家了!
And thanks for great explanations to all of you!
推荐答案
国家管理从桌面应用程序的角度来网络世界,当掌握了关键的东西。
State management is a critical thing to master when coming to Web world from a desktop application perspective.
-
会话
用于存储的每用户作为当前Web会议上的服务器的信息。它支持使用数据库服务器作为后端存储。 -
饼干
应该用来存储每用户作为对当前Web会话或永久资料信息的客户的,因此客户有过cookie的内容控制。 -
缓存
对象的在一个单一的应用程序的用户之间共享即可。其主要目的是为了从数据存储缓存的数据和不应该被用作主存储器。它支持的自动失效的功能。 -
应用
对象用户存储的应用范围状态,应进行相应使用之间共享。
Session
is used to store per-user information for the current Web session on the server. It supports using a database server as the back-end store.Cookie
should be used to store per-user information for the current Web session or persistent information on the client, therefore client has control over the contents of a cookie.Cache
object is shared between users in a single application. Its primary purpose is to cache data from a data store and should not be used as a primary storage. It supports automatic invalidation features.Application
object is shared between users to store application-wide state and should be used accordingly.
如果您的应用程序使用了一些未经授权的用户,我建议你将数据存储在cookie中。如果需要验证,您可以手动存储在数据库中的数据,或使用ASP.NET配置文件管理功能。
If your application is used by a number of unauthenticated users, I suggest you store the data in a cookie. If it requires authentication, you can either store the data in the DB manually or use ASP.NET profile management features.
这篇关于缓存VS会话VS饼干?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!