Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ClientBase<TChannel>.CacheSetting #4696

Merged
merged 3 commits into from
Aug 25, 2021

Conversation

mconnew
Copy link
Member

@mconnew mconnew commented Aug 20, 2021

This will help with #4186. We should do some follow-up work to have dotnet-svcutil emit the code to turn on caching as the only constructor on ClientBase<TChannel> that has caching turned on by default is the configuration based constructors which we don't support.

@mconnew mconnew changed the title Add support for ClientBase<T>.CacheSetting Add support for ClientBase<TChannel>.CacheSetting Aug 20, 2021
@mconnew
Copy link
Member Author

mconnew commented Aug 21, 2021

I've added some additional caching so that there's a benefit even when you don't use the ClientBase<TChannel>.CacheSettings property. I added caching with a weak reference in TypeLoader so that repeated calls to ContractDescription.GetContract(Type contractType) will return the same instance. This means repeatedly instantiating a ChannelFactory for the same interface contract will return the same ContractDescription instance. There is a potential issue where if someone modifies the cached ContractDescription, they get the same modified instance returned instead of a fresh instance. To mitigate this, I made it so that only ChannelFactory uses the cached mechanism. ContractDescription.GetContract will continue to return a new instance each time. If someone is going to modify the ContractDescription, this is the way I would expect them to do so.

@mconnew mconnew merged commit dde5e7f into dotnet:main Aug 25, 2021
@mconnew mconnew deleted the AddClientBaseCaching branch October 11, 2023 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants