Added channel caching by host string

pull/1593/head
murgatroid99 10 years ago
parent e02c148271
commit ec4e5cf212
  1. 14
      src/objective-c/GRPCClient/private/GRPCChannel.m

@ -40,9 +40,19 @@
@implementation GRPCChannel
// TODO(mlumish): Investigate whether a cache with strong links is a good idea
static NSMutableDictionary *channelCache;
+ (instancetype)channelToHost:(NSString *)host {
// TODO(jcanizales): Reuse channels.
return [[self alloc] initWithHost:host];
if (channelCache == nil) {
channelCache = [NSMutableDictionary dictionary];
}
GRPCChannel *channel = channelCache[host];
if (channel == nil) {
channel = [[self alloc] initWithHost:host];
channelCache[host] = channel;
}
return channel;
}
- (instancetype)init {

Loading…
Cancel
Save