diff options
author | Jorge Canizales <jcanizales@gmail.com> | 2015-05-14 13:56:39 -0700 |
---|---|---|
committer | Jorge Canizales <jcanizales@gmail.com> | 2015-05-14 13:56:39 -0700 |
commit | 96ea30362c24a8b722ef5020684e648521387f10 (patch) | |
tree | 321eb4ffb911a9ac9798e55a2672075a4e3cd2ce | |
parent | e02c1482716466ccc5fa2dab8a632dee1020e5d1 (diff) | |
parent | dda9a3cd369726ebf88568f38c85bd4fc9db9094 (diff) |
Merge pull request #1593 from murgatroid99/objective_c_channel_cache
Added channel caching by the user-provided host string.
-rw-r--r-- | src/objective-c/GRPCClient/private/GRPCChannel.m | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.m b/src/objective-c/GRPCClient/private/GRPCChannel.m index 8b7055815d..36f4c0aa5e 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannel.m +++ b/src/objective-c/GRPCClient/private/GRPCChannel.m @@ -41,8 +41,18 @@ @implementation GRPCChannel + (instancetype)channelToHost:(NSString *)host { - // TODO(jcanizales): Reuse channels. - return [[self alloc] initWithHost:host]; + // TODO(mlumish): Investigate whether a cache with strong links is a good idea + static NSMutableDictionary *channelCache; + static dispatch_once_t cacheInitialization; + dispatch_once(&cacheInitialization, ^{ + channelCache = [NSMutableDictionary dictionary]; + }); + GRPCChannel *channel = channelCache[host]; + if (!channel) { + channel = [[self alloc] initWithHost:host]; + channelCache[host] = channel; + } + return channel; } - (instancetype)init { |