Skip to content

Commit

Permalink
Merge pull request #11 from emac/master
Browse files Browse the repository at this point in the history
Double check whether the table exists or not when creating new one
  • Loading branch information
muesli authored Jul 4, 2017
2 parents 21535fd + 0280a23 commit a299e7f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ func Cache(table string) *CacheTable {
mutex.RUnlock()

if !ok {
t = &CacheTable{
name: table,
items: make(map[interface{}]*CacheItem),
}

mutex.Lock()
cache[table] = t
t, ok = cache[table]
// Double check whether the table exists or not.
if !ok {
t = &CacheTable{
name: table,
items: make(map[interface{}]*CacheItem),
}
cache[table] = t
}
mutex.Unlock()
}

Expand Down

0 comments on commit a299e7f

Please sign in to comment.