Skip to content

Commit

Permalink
Double check whether the table exists or not when creating new one
Browse files Browse the repository at this point in the history
  • Loading branch information
Emac committed Jul 4, 2017
1 parent 21535fd commit 0280a23
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 0280a23

Please sign in to comment.