aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/GRPCClient/private
diff options
context:
space:
mode:
authorGravatar Jan Tattermusch <jtattermusch@users.noreply.github.com>2016-06-30 13:43:23 -0700
committerGravatar GitHub <noreply@github.com>2016-06-30 13:43:23 -0700
commita5596db1a53723789d7c90c23d9cbfbb8207f949 (patch)
tree45efa15a49b77b7c3d317e88807a688900e55853 /src/objective-c/GRPCClient/private
parent8ecf5f5a21e6bed0ee47e195f11f3634aa0157e9 (diff)
parent75fe9ba8b32c7a5945b23b1cc53a05c6a14617bd (diff)
Merge pull request #6378 from jcanizales/let-invalidate-channels
Add a maybe-temporary way for apps to clear the channel cache
Diffstat (limited to 'src/objective-c/GRPCClient/private')
-rw-r--r--src/objective-c/GRPCClient/private/GRPCHost.h2
-rw-r--r--src/objective-c/GRPCClient/private/GRPCHost.m21
2 files changed, 18 insertions, 5 deletions
diff --git a/src/objective-c/GRPCClient/private/GRPCHost.h b/src/objective-c/GRPCClient/private/GRPCHost.h
index 9220e2a33d..350c69bf8e 100644
--- a/src/objective-c/GRPCClient/private/GRPCHost.h
+++ b/src/objective-c/GRPCClient/private/GRPCHost.h
@@ -41,6 +41,8 @@ struct grpc_channel_credentials;
@interface GRPCHost : NSObject
++ (void)flushChannelCache;
+
@property(nonatomic, readonly) NSString *address;
@property(nonatomic, copy, nullable) NSString *userAgentPrefix;
@property(nonatomic, nullable) struct grpc_channel_credentials *channelCreds;
diff --git a/src/objective-c/GRPCClient/private/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCHost.m
index fef6385cea..08c699f99e 100644
--- a/src/objective-c/GRPCClient/private/GRPCHost.m
+++ b/src/objective-c/GRPCClient/private/GRPCHost.m
@@ -51,6 +51,8 @@ NS_ASSUME_NONNULL_BEGIN
// templates/src/core/surface/version.c.template .
#define GRPC_OBJC_VERSION_STRING @"0.13.0"
+static NSMutableDictionary *kHostCache;
+
@implementation GRPCHost {
// TODO(mlumish): Investigate whether caching channels with strong links is a good idea.
GRPCChannel *_channel;
@@ -82,13 +84,12 @@ NS_ASSUME_NONNULL_BEGIN
}
// Look up the GRPCHost in the cache.
- static NSMutableDictionary *hostCache;
static dispatch_once_t cacheInitialization;
dispatch_once(&cacheInitialization, ^{
- hostCache = [NSMutableDictionary dictionary];
+ kHostCache = [NSMutableDictionary dictionary];
});
- @synchronized(hostCache) {
- GRPCHost *cachedHost = hostCache[address];
+ @synchronized(kHostCache) {
+ GRPCHost *cachedHost = kHostCache[address];
if (cachedHost) {
return cachedHost;
}
@@ -96,12 +97,22 @@ NS_ASSUME_NONNULL_BEGIN
if ((self = [super init])) {
_address = address;
_secure = YES;
- hostCache[address] = self;
+ kHostCache[address] = self;
}
}
return self;
}
++ (void)flushChannelCache {
+ @synchronized(kHostCache) {
+ [kHostCache enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key,
+ GRPCHost * _Nonnull host,
+ BOOL * _Nonnull stop) {
+ [host disconnect];
+ }];
+ }
+}
+
- (nullable grpc_call *)unmanagedCallWithPath:(NSString *)path
completionQueue:(GRPCCompletionQueue *)queue {
GRPCChannel *channel;