在MVC 2存储用户数据 [英] Store user data in MVC 2

查看:103
本文介绍了在MVC 2存储用户数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,当一个用户来到我的网页,还有就是我想从他们如何与页面交互存储某些数据。这个数据没有被坚持,虽然,所以我试图找出做到这一点的最好办法。

So when a user comes to my page, there is certain data that I want to store from how they are interacting with the page. None of this data is being persisted though, so I'm trying to figure out the best way to do it.

例如,他们登录到我的网页,我通过JavaScript得到他们的位置/ Google地图。我应该存储在会话?我也通过JavaScript获得他们的IP。如果我只是做的JavaScript查询每次我需要使用它,或者我应该存储在会话中呢?

For example, they log onto my page, and I'm getting their location through javascript/google maps. Should I store that in the session? I'm also getting their IP through javascript. Should I just make the javascript query everytime I need to use it or should I store that in the session as well?

时cacheing不是存储在会话事情变得更好?我应该把所有这一切在模式,把模式在缓存中,然后用的Guid 来retirve权模式在缓存正确的用户?这会变得疯狂昂贵的,如果成千上万的用户都在页面上一次?

Is cacheing better than storing things in the session? Should I put this all in a model, put the model in the cache, and then use a Guid to retirve the right model for the right user in the cache? Would this get crazy expensive if thousands of users were on the page at once?

用户还能够得到使用这个信息,我收集的PARAMS到一个存储过程从数据库记录列表。这个名单有时需要被重新用于查询,但其他时候,它只需在网页被重新排序。我不会想查询所有这些,每次我只是通过它的排序,但将缓存能容纳像这成千上万的记录每个用户登录?

Users are also able to get a list of records from the database using this information that I'm gathering as params to a stored proc. This list sometimes needs to be re-queried for, but other times, it just needs to be re-sorted on the page. I wouldn't want to query for all of these everytime I'm just sorting through it, but would the cache be able to hold like thousands of records in it for each user logged in?

我刚刚从未遇到过这种东西在MVC之前,所以我可以用一些指导来了。

I've just never came across this stuff in MVC before so I could use a little guidance.

谢谢你们。

推荐答案

如果您想通过用户的访问过程中坚持某些用户数据,您可以使用ASP.NET会话cookie或其他一些更长期的持续性中等如一个数据库。我通常存储用户数据,因为这是序列化到JSON,加密并写入到一个cookie对象。这让我坚持在多个访问的数据,即使他们离开和回来。

If you want to persist some user data through the course of the user's visit, you can use the ASP.NET session, cookies or some other more permanent persistence medium such as a database. I typically store user data as objects that are serialized to json, encrypted and written out to a cookie. This allows me to persist the data across multiple visits, even if they leave and come back.

据缓存数据,有很多的选择和ASP.NET有一些不错的内置功能,使您更容易。当您缓存数据它会在内存存储在Web服务器上,除非你安装一个外部缓存服务器,如memcached的。缓存的数据可以在多个用户之间共享,如果它是普通的数据,以消除浪费的缓存。您还可以设置缓存失效,所以如果该数据变成旧的缓存被自动清除。

As far as caching data, there are many choices and ASP.NET has some nice built in features to make it easier for you. When you cache data it will be store in the memory on your web server, unless you setup an external caching server such as memcached. The cached data can be shared between multiple users if it is common data, to eliminate wasteful caching. You can also set up caching invalidation so the cache gets automatically cleared if the data becomes old.

至于数据高速缓存容量,这将取决于你什么缓存,这些对象有多大都是在内存中,有多少用户将被创建这些缓存的对象,多少内存你的服务器有提供。

As far as amount of data to cache, that will depend on what you're caching, how large those objects are in memory, how many users will be creating these cached objects, and how much memory your server has available.

在理想情况下,你可能需要计算出来,以确定费用将是什么。

Ideally you would want to calculate it out to determine what the cost will be.

这篇关于在MVC 2存储用户数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆