简体   繁体   English

在会话中存储我的自定义类的1000多个实例的列表是否是内存问题?

[英]Is storing List of 1000+ instance of my custom class in session a memory problem?

Is storing a list of 1000 instance of my custom class to the session variable a good approach ? 将自定义类的1000个实例的列表存储到会话变量中是一种好方法吗? My asp.net web app need multilingual support and i am storing the labels in a table.I will have multiple users who has their own language preference and text(label content) preference. 我的asp.net Web应用程序需要多语言支持,并且我将标签存储在表格中。我将有多个用户,他们具有自己的语言首选项和文本(标签内容)首选项。

I am thinking about loading the labels and store it in session variable and access that to use in the pages.Storing it in Application variable does not work because each customer have their own text for the labels.So is storing session a good way of doing this ? 我正在考虑加载标签并将其存储在会话变量中并访问要在页面中使用的标签。将其存储在Application变量中不起作用,因为每个客户都有自己的标签文本,因此存储会话是一种很好的方法这个 ? I guess i will have almost 1000 labels as of now and it may increase as the application grows. 我想到目前为止,我将拥有近1000个标签,并且随着应用程序的增长,它可能会增加。

My custom class has 2 proprties. 我的自定义类有2个属性。 LanguageCode and LanguageName 语言代码和语言名称

for some reason i cant use asp.net Resource files :( 由于某些原因,我无法使用asp.net资源文件:(

Whats your thoughts on this ? 您对此有何看法?

您应该为每种语言存储一组标签,然后在会话中存储语言名称并使用它来查找正确的标签集。

Some thoughts to notice: 需要注意的一些想法:

If your managers have something in particular against resx's, you can store all those labels in any other format (eg plain text files), or in a DB. 如果您的经理特别反对resx,则可以将所有这些标签以任何其他格式(例如纯文本文件)或DB存储。

If you have little amount of users, and loading time is extremely crucial, your managers may have a point. 如果您的用户数量很少,并且加载时间非常关键,那么您的经理可能会有所作为。 Other than that, they're wrong, and I would consider trying to explain that to them. 除此之外,它们是错误的,我会考虑尝试向他们解释。

Try considering "computing" the labels at runtime (eg if some of them include adding prefixes, suffixes, etc. you can save only the "stems" and provide a relevant label only on demand. That will save you some server space). 尝试在运行时考虑“计算”标签(例如,如果其中一些包含添加前缀,后缀等,则可以仅保存“词根”并仅在需要时提供相关标签。这将节省一些服务器空间)。

如果您是我,那么我将首先花一些时间来弄清楚为什么您的资源文件不起作用...只要您将Thread.CurrentThread.CurrentCulture(或CurrentUICulture?)值设置为特定的区域性,并且将资源文件放置在正确的位置,我想不出任何原因说明为什么它不起作用。

Not a good idea, there are two problems with it: 这不是一个好主意,它有两个问题:

  • It will use up the memory on the server, and reduce the number of users that can use the system 它将耗尽服务器上的内存,并减少可以使用系统的用户数量
  • The time for each request will increase 每个请求的时间将增加

The standard way to do this is using RESX (resource) files. 执行此操作的标准方法是使用RESX(资源)文件。 You should try to fix that. 您应该尝试解决该问题。

Why not use Application variable and create as many Application variables as the languages you have. 为什么不使用Application变量并创建与您所使用的语言一样多的Application变量。 Each application variable will be a superset of all the labels for that language. 每个应用程序变量将是该语言的所有标签的超集。
Or maybe store the entire table(s) in application variable(s), instead of storing multiple session variables that, I assume, they intersect with each other. 或者,也许将整个表存储在应用程序变量中,而不是存储多个我认为它们相互交叉的会话变量。

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

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