Skip to content
Snippets Groups Projects
Commit dda9a3cd authored by murgatroid99's avatar murgatroid99
Browse files

Made cache thread-safe

parent ec4e5cf2
No related branches found
No related tags found
No related merge requests found
......@@ -40,15 +40,15 @@
@implementation GRPCChannel
// TODO(mlumish): Investigate whether a cache with strong links is a good idea
static NSMutableDictionary *channelCache;
+ (instancetype)channelToHost:(NSString *)host {
if (channelCache == nil) {
// 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 == nil) {
if (!channel) {
channel = [[self alloc] initWithHost:host];
channelCache[host] = channel;
}
......
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