mutexes
This commit is contained in:
parent
2d54824f47
commit
d7ef1bb949
7
main.go
7
main.go
|
@ -77,13 +77,11 @@ func (c *MetadataCache) Get(o int64, k string) ([]string, error) {
|
|||
log.Printf("Get %d, %s.\n", o, k)
|
||||
// Check cache for entry
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
object, ok := c.objects[o]
|
||||
if !ok {
|
||||
// Object is not in the cache so let's load it up
|
||||
var tmpobject metadataObject
|
||||
c.objects[o] = tmpobject
|
||||
c.lock.RUnlock()
|
||||
tmpobject.loading.Do(func() {
|
||||
// Only do this once even if concurrent requests come in
|
||||
tmpobject.entries = loadDbEntries(c.objectType, o)
|
||||
|
@ -91,11 +89,12 @@ func (c *MetadataCache) Get(o int64, k string) ([]string, error) {
|
|||
object = tmpobject
|
||||
|
||||
}
|
||||
c.lock.RUnlock()
|
||||
|
||||
object.lock.RLock()
|
||||
defer object.lock.RUnlock()
|
||||
// Load entries from db
|
||||
entries, ok := object.entries[k]
|
||||
object.lock.RUnlock()
|
||||
|
||||
object.lock.Lock()
|
||||
object.lastHit=time.Now()
|
||||
object.lock.Unlock()
|
||||
|
|
Loading…
Reference in New Issue