Merge pull request #1593 from murgatroid99/objective_c_channel_cache

Added channel caching by the user-provided host string.
pull/1596/head
Jorge Canizales 10 years ago
commit 96ea30362c
  1. 14
      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 {

Loading…
Cancel
Save