gpt4 book ai didi

WCF ChannelFactory 缓存

转载 作者:行者123 更新时间:2023-12-01 05:46:07 26 4
gpt4 key购买 nike

我刚读过这篇 great article董文龙关于 WCF ChannelFactory 缓存的文章。

我的问题很简单,你怎么能证明 ChannelFactory 实际上是在调用之间被缓存的?我遵循了有关 ClientBase 构造函数的规则。我们在继承自 ClientBase 的对象上使用以下重载构造函数:

ClientBase(string endpointConfigurationName, EndpointAddress remoteAddress);

在上面提到的文章中指出:

For these constructors, all arguments (including default ones) are in the following list:

· InstanceContext callbackInstance

· string endpointConfigurationName

· EndpointAddress remoteAddress

As long as these three arguments are the same when ClientBase is constructed, we can safely assume that the same ChannelFactory can be used. Fortunately, String and EndpointAddress types are immutable, i.e., we can make simple comparison to determine whether two arguments are the same. For InstanceContext, we can use Object reference comparison. The type EndpointTrait is thus used as the key of the MRU cache.



为了测试 ChannelFactory 缓存理论,我们正在检查 ClientBase 构造函数中的 Hashcode,例如var testHash = RuntimeHelpers.GetHashCode(base.ChannelFactory);

调用之间的哈希值不同,这使我们认为 ChannelFactory 实际上没有被缓存。

有什么想法吗?

问候

迈尔斯

最佳答案

我知道这个问题有点老了,但是没有答案,如果有人有同样的问题:

从你提到的文章中:

Before the inner channel (the transparent proxy) of ClientBase is created, the caching logic for the current ClientBase can be disabled if other public properties (such as ChannelFactory, Endpoint, and ClientCredentials) are accessed.



这意味着调用 ChannelFactory.GetHashCode()反对 ClientBase<IService> instance 实际上会导致缓存被禁用。

关于WCF ChannelFactory 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2107203/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com