aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c
diff options
context:
space:
mode:
authorGravatar murgatroid99 <mlumish@google.com>2015-05-14 11:34:40 -0700
committerGravatar murgatroid99 <mlumish@google.com>2015-05-14 11:34:40 -0700
commitec4e5cf212219432b7512a39186dd73bcebe7e51 (patch)
treee62638e45ff92eff326d340d7aee13ee6f46e0c9 /src/objective-c
parente02c1482716466ccc5fa2dab8a632dee1020e5d1 (diff)
Added channel caching by host string
Diffstat (limited to 'src/objective-c')
-rw-r--r--src/objective-c/GRPCClient/private/GRPCChannel.m14
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..e1aebdfe57 100644
--- a/src/objective-c/GRPCClient/private/GRPCChannel.m
+++ b/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 {