正确使用DataCacheFactory [英] utilizing DataCacheFactory properly

查看:101
本文介绍了正确使用DataCacheFactory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能否告诉我这是否是实现这一目标的正确方法[即利用DataCacheFactory],在一个页面的上下文中,任何有链接的人都可以访问的asp web应用程序[即不使用会话] -
$


这是我目前正在使用的[没有收到任何错误,但想确保我正确使用这个]


私有静态DataCacheFactory dataCacheFactory = new DataCacheFactory();

protected void Page_Load (对象发件人,EventArgs e)

{

if(IsPostBack)getResults();

}

protected void getResults()

{

DataCache dataCache = dataCacheFactory.GetDefaultCache();

//其余代码。 ..使用dataCache实例进行put和get ...

}



OR,我应该这样做 - 在方法之外声明dataCache obj -




私有静态DataCacheFactory dataCacheFactory = new DataCacheFactory( );

私有DataCache dataCache = null;

protected void Page_Load(object sender,EventArgs e)

{

if(IsPostBack)getResults();

}

protected void getResults( )

{

dataCache = dataCacheFactory.GetDefaultCache();

//其余代码...使用dataCache实例进行put和get ...

}


谢谢!

解决方案

以这种方式使用DataCacheFactory没有任何问题。如果您同时保留DataCache的句柄并且不在每次访问缓存时调用GetDefaultCache,它会更快。




Hi, can you tell me if this would be the correct way of achieving this [i.e. utilizing DataCacheFactory], in the context of a one page, asp web application that anyone with a link can access [i.e. not using sessions] -

Here is what I am currently using [not getting any errors, but want to make sure I'm using this correctly]

private static DataCacheFactory dataCacheFactory = new DataCacheFactory();
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack) getResults();
}
protected void getResults()
{
DataCache dataCache = dataCacheFactory.GetDefaultCache();
// rest of code... use dataCache instance for put and get...
}

OR, should I do this like this -- declaring the dataCache obj outside the method -

private static DataCacheFactory dataCacheFactory = new DataCacheFactory();
private DataCache dataCache = null;
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack) getResults();
}
protected void getResults()
{
dataCache = dataCacheFactory.GetDefaultCache();
// rest of code... use dataCache instance for put and get...
}

Thanks!

解决方案

There is nothing wrong with using DataCacheFactory this way. It will be even faster if you keep the handle to DataCache also and don't call GetDefaultCache on every cache access.


这篇关于正确使用DataCacheFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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