当存储的AppFabric DataCacheFactory在Asp.net?DataCacheFactory、AppFabric、net、Asp

由网友(我爱你)分享简介:AppFabric中的DataCacheFactory需要很长的时间进行初始化,所以我想,一旦创建并在接下来的请求重新使用它。 AppFabric's DataCacheFactory takes long time to initialize so I am trying to create it once an...

AppFabric中的DataCacheFactory需要很长的时间进行初始化,所以我想,一旦创建并在接下来的请求重新使用它。

AppFabric's DataCacheFactory takes long time to initialize so I am trying to create it once and re-use it in next requests.

目前,最好的办法我已经是将其存储在HttpContext的,但我也有一些WCF服务(不具备的HttpContext套)。任何其他的想法在这里,我应该怎么处理呢?

Currently, the best idea I have is to store it in HttpContext but I also have some WCF services (which don't have HttpContext set). Any other ideas where and how I should handle this?

谢谢!

推荐答案

这是一个问题,我已经给了一些思想,在过去几个月,但我还没有拿出一个明确的答案......

This is a problem I've been giving some thought to over the last couple of months, but I haven't come up with a definitive answer...

我不知道HttpContext的是正确的地方,以保持它 - 根据的此页面一个新的HttpContext对象将在请求的开始被创建,当请求完成后销毁,所以我会担心,如果你把DataCacheFactory到的HttpContext你将失去它当请求管道完成。 (HttpContext的是不是我特别需要使用,所以我可以有这个完全错误的对象!)

I'm not sure HttpContext is the right place to keep it - according to this page "A new HttpContext object will be created at the beginning of a request and destroyed when the request is completed", so I'd be concerned that if you put DataCacheFactory into HttpContext you're going to lose it when the request pipeline completes. (HttpContext isn't an object I've particularly needed to use so I could have this completely wrong!)

不过,我认为有多种选择:

However, I think there are a number of options:

如果您使用 Singleton模式 用于创建DataCacheFactory(乔恩 飞碟双向具有的优秀的的片上 做单身在C#中使用 线程安全这里)时, 辛格尔顿将主要照顾 存储DataCacheFactory为 您在实例字段。

If you use the Singleton pattern for creating a DataCacheFactory (Jon Skeet has an excellent piece on doing Singletons in C# with thread-safety here), the Singleton will essentially take care of storing the DataCacheFactory for you in the instance field.

这个选项感觉稍微不正当的,但你可以让你的DataCacheFactory在ASP.NET缓存。没有一个WCF开发者,我不知道你有访问,但如果你能到达的httpRuntime对象缓存是从那里访​​问。

This option feels slightly perverse but you could keep your DataCacheFactory in the ASP.NET Cache. Not being a WCF developer I don't know what you've got access to but if you can get to the HttpRuntime object the cache is accessible from there.

你可能要考虑的是存储DataCacheFactory在应用程序状态,虽然我觉得这可能也很难从你的WCF服务的机会,因为它的通常是通过HttpContext的。访问的另一种选择

Another option you might want to consider is storing DataCacheFactory in Application state, although I think this might also be difficult to access from your WCF services as it's typically accessed through HttpContext.

阅读全文

相关推荐

最新文章