在 Web 服务调用之间共享对象实例
我有一个初始化成本相对较高的对象,它提供了处理Web服务请求所需的线程安全计算方法。
我正在寻找在请求之间保持初始化实例可用的最佳方法。
一种方法是将其声明为静态变量。然后它将保持可用,直到 AppDomain 被回收。
这是一个不使用 WCF 的较旧的 Web 服务,但如果转换可以提供更好的解决方案,那么转换也是一种选择。
有更好的方法吗?
I have an object that has relatively high initialization cost that provides a thread-safe calculation method needed to process web service requests.
I'm looking for the best way to keep an initialized instance available between requests.
One method is to declare it as a static variable. It would then remain available until the AppDomain is recycled.
This is an older web service that does not use WCF, but converting is an option if that would provide a better solution.
Is there a better approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
HttpRuntime.Cache
中缓存对象怎么样?在这里,我将其在缓存中保留最多一个小时,但您可以根据需要更改此设置。
What about caching the object in
HttpRuntime.Cache
?Here I leave it in the cache for up to an hour, but you can vary this as needed.