【发布时间】:2015-03-08 10:37:27
【问题描述】:
缓存和共享类是应用程序范围的。我知道一些细节,但这里是场景:
我将参数保存在数据库中。 我将它们读入数据表并将它们存储在缓存中。 每当我需要时,我将缓存变量直接转换为数据表,查询它并获得结果。 所以我不是每次都使用sql server。
替代方案是: 读取数据库并将其存储在类共享变量中 每当需要时,我都会使用这个共享变量(数据表)并查询它。 如果这个变量是空的,我会从 db 中填充 ilt。 由于变量是数据表,我不需要直接转换它。
哪一个更受欢迎?或者我可以使用它们中的任何一个,因为没有区别。
这个类不是一个特殊的类。仅包含从数据库读取参数的函数。为了加快速度,我开始使用 aspnet 缓存,但我注意到我不需要,因为类变量可以处理。
有什么建议吗?你能想到这个场景的任何可能结果吗?只适用于不会改变的参数?
class Class1
private shared localVar as datatable
public shared function readParam1 as string -- this is my old method
... SELECT from params table
return value
end function
public shared function readParam2 as string -- then I implemented this
if httpcontext.cache variable is empty then
... SELECT from params table
... set cache variable
end if
value = directcast(cachevalue, string)
return value
end function
public shared function readParam3 as string -- now I'm planing to use this
if localVar is empty then
... SELECT from params table
... slocalVar = sql table
end if
value = select value with localVar.Select function
return value
end function
end class
【问题讨论】:
-
如果值不会改变,我会将它们存储在共享成员中,唯一的区别是我还会在应用程序启动时加载值。
标签: asp.net vb.net class caching shared