Skip to content
Snippets Groups Projects
Commit 96ea3036 authored by Jorge Canizales's avatar Jorge Canizales
Browse files

Merge pull request #1593 from murgatroid99/objective_c_channel_cache

Added channel caching by the user-provided host string.
parents e02c1482 dda9a3cd
No related branches found
No related tags found
No related merge requests found
......@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment