Skip to content

Commit

Permalink
ensureConnectionCache should only create a cache if one does not exist.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaidaguerre committed Nov 2, 2023
1 parent 8adf4d8 commit bcdd15b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,21 @@ func (p *Plugin) shutdown() {
}

func (p *Plugin) ensureConnectionCache(connectionName string) (*connectionmanager.ConnectionCache, error) {
p.connectionCacheMapLock.Lock()
defer p.connectionCacheMapLock.Unlock()

// check if we already have a cache
if cache, ok := p.connectionCacheMap[connectionName]; ok {
return cache, nil
}

// add to map of connection caches
maxCost := int64(100000 / len(p.ConnectionMap))
connectionCache, err := connectionmanager.NewConnectionCache(connectionName, maxCost)
if err != nil {
return nil, err
}

p.connectionCacheMapLock.Lock()
defer p.connectionCacheMapLock.Unlock()
// add to map of connection caches
p.connectionCacheMap[connectionName] = connectionCache
return connectionCache, nil
}
Expand Down

0 comments on commit bcdd15b

Please sign in to comment.