存储查找变量的最佳方法? [英] Best way to store lookup variables?

查看:64
本文介绍了存储查找变量的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Session变量中存储角色的信息。 RoleA

有一组特定的值,RoleB有一个特定的集合。

当我访问RoleA的值时,它看起来像这样:


Session [Utils.RoleA_MBcount] =" 30"

Session [Utils.RoleA_BandwidthLimit] =" 1000"

Session [Utils.RoleA_FeatureCcountLimit] =" 10"


和其他角色类似。这些值最初从数据库加载

。每个角色实际上都是购买计划。类似于

各种托管计划,可以为您提供更多的支付。一旦将

角色初始化为Session变量,我只需访问

Session变量来检查用户限制。


每个Utils中的上述属性是一个静态字符串引用。

他们只是很好的方式给我智能感知并避免硬编码

字符串无处不在。问题是每次我想使用这些查找值时,我都必须点击Utils.cs

文件。如果有四个

角色,并且每个角色都有10个属性可能会有大量点击

(尤其是角色更多),具体取决于查找的分组方式

整个应用程序。


这是一个问题还是有更好的方法?


谢谢,
John

I''d like to store information for roles in Session variables. RoleA
has a specific set of values, RoleB has a specific set and so one.
When I access values for RoleA, it looks like this:

Session[Utils.RoleA_MBcount] = "30"
Session[Utils.RoleA_BandwidthLimit] = "1000"
Session[Utils.RoleA_FeatureBcountLimit] = "5"
Session[Utils.RoleA_FeatureCcountLimit] = "10"

and similar for the other roles. Those values are initially loaded
from a database. Each role is actually a purchased plan. Similar to
various hosting plans that give you more the more you pay. Once the
roles are initialized into Session variables, I just access the
Session variable to check user limits.

Each of the above properties in Utils is a static string reference.
They''re just nice ways to give me intellisense and avoid hard coding
strings everywhere. The problem is that I''ll have to hit the Utils.cs
file everytime I want to use these lookup values. If there are four
roles and each one has 10 properties that could be a lot of hits
(especially with more roles) depending on how grouped the lookups are
through out the app.

Is this a concern or is there a better way?

Thanks,
John

推荐答案

" john_c" < jo *** @ bigstring.comwrote in message

news:11 ********************** @ a75g2000cwd.googlegr oups .com ...
"john_c" <jo***@bigstring.comwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...

问题是每次我想要使用
时我都必须点击Utils.cs文件这些查找值。
The problem is that I''ll have to hit the Utils.cs file everytime I want to
use these lookup values.



实际上,你不是...... Utils.cs文件,就像你所有的其他C#代码文件一样,

是在重建应用程序时编译到您的Web应用程序的DLL中,这是在应用程序启动时加载到内存中的
...

In fact, you don''t... The Utils.cs file, like all your other C# code files,
is compiled up into your web app''s DLL when you rebuild the app, which is
loaded into memory when the app starts...


这是一个问题还是有更好的方法?
Is this a concern or is there a better way?



我不会认为这是一个问题...


至于更好的方式,那个' '有点难以说......其他方面肯定有

- 你可以使用其中一个Collection对象(例如ArrayList)或

泛型对象(例如Dictionary)如果您正在使用ASP.NET v2,或者您可以在会话中单独保存每个元素 - 如果有任何性能

差异,我们可能正在寻找在纳秒......

I wouldn''t have thought it was a concern...

As for a better way, that''s a little difficult to say... There are certainly
other ways - you could use one of the Collection objects (e.g. ArrayList) or
Generics objects (e.g. Dictionary) if you''re using ASP.NET v2, or you could
hold each element separately in Session - if there are any performance
differences, we''re probably looking at nanoseconds...


2月20日下午3:34,Mark Rae < m ... @ markNOSPAMrae.comwrote:
On Feb 20, 3:34 pm, "Mark Rae" <m...@markNOSPAMrae.comwrote:

" john_c" < j ... @ bigstring.comwrote in message


新闻:11 ********************** @ a75g2000cwd.googlegr oups.com ...
"john_c" <j...@bigstring.comwrote in message

news:11**********************@a75g2000cwd.googlegr oups.com...

问题是我每次都要点击Utils.cs文件

使用这些查找值。
The problem is that I''ll have to hit the Utils.cs file everytime I want to
use these lookup values.



实际上,你不是...... Utils.cs文件,就像你所有的其他C#代码文件一样,

是在重建应用程序时编译到您的Web应用程序的DLL中,这是在应用程序启动时加载到内存中的
...


In fact, you don''t... The Utils.cs file, like all your other C# code files,
is compiled up into your web app''s DLL when you rebuild the app, which is
loaded into memory when the app starts...



你是对的马克。谢谢。我想是静态的 accessor扔给我

off。这些静态属性是否会在内存中保留

用户会话或应用会话的长度?

You''re right Mark. Thanks. I guess the "static" accessor threw me
off. Do these static properties stay in memory for the length of the
user session or app session?


>
>

这是一个问题还是有更好的方法?
Is this a concern or is there a better way?



我不会认为这是一个问题...


至于更好的方式,那个' '有点难以说......其他方面肯定有

- 你可以使用其中一个Collection对象(例如ArrayList)或

泛型对象(例如Dictionary)如果您正在使用ASP.NET v2,或者您可以在会话中单独保存每个元素 - 如果有任何性能

差异,我们可能正在寻找在纳秒...


I wouldn''t have thought it was a concern...

As for a better way, that''s a little difficult to say... There are certainly
other ways - you could use one of the Collection objects (e.g. ArrayList) or
Generics objects (e.g. Dictionary) if you''re using ASP.NET v2, or you could
hold each element separately in Session - if there are any performance
differences, we''re probably looking at nanoseconds...



我使用的是ASP.NET 2.0。可以使用一个集合,但我认为更好的方法是在Utils类中按静态类对每个角色进行分组,

这也是静态的。这只是一个很好的intellisense布局。所以

你会得到


Session [Utils.Roles.RoleA.MBcount]

Session [Utils.Roles.RoleA。 BandwidthLimit]

Session [Utils.Roles.RoleA.FeatureBcountLimit]

Session [Utils.Roles.RoleA.FeatureCcountLimit]

I am using ASP.NET 2.0. A collection could be used but I think a
better way is to group each role by static class in the Utils class,
which is also static. This just gives a nice intellisense layout. So
you would have

Session[Utils.Roles.RoleA.MBcount]
Session[Utils.Roles.RoleA.BandwidthLimit]
Session[Utils.Roles.RoleA.FeatureBcountLimit]
Session[Utils.Roles.RoleA.FeatureCcountLimit]


此外,每个计划都有相应的应用程序缓存。

将用户会话值与之进行比较。这意味着只需要在应用程序加载时为每个新用户点击

数据库

(会话)。

Also, there will be corresponding Application cache for each plan.
The user Session values are compared against it. This means the
database only needs to be hit when the app loads and for each new user
(session).


这篇关于存储查找变量的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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