diff options
author | Ben Morrison <ben@gbmor.dev> | 2019-05-27 19:01:04 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2019-05-27 19:01:04 -0400 |
commit | d6d0c18cad6426a0562d19b2b0c66a7c2bb4e2c5 (patch) | |
tree | 0157890c7bf462db415ad0ed59828576496b2685 /cache.go | |
parent | 6f9383517d8dbee557d2b52113e20e08207b533e (diff) | |
download | getwtxt-d6d0c18cad6426a0562d19b2b0c66a7c2bb4e2c5.tar.gz |
fixed race condition
Diffstat (limited to 'cache.go')
-rw-r--r-- | cache.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/cache.go b/cache.go index 4cb1855..e0fedb1 100644 --- a/cache.go +++ b/cache.go @@ -14,11 +14,19 @@ import ( ) func checkCacheTime() bool { - return time.Since(confObj.LastCache) > confObj.CacheInterval + confObj.Mu.RLock() + answer := time.Since(confObj.LastCache) > confObj.CacheInterval + confObj.Mu.RUnlock() + + return answer } func checkDBtime() bool { - return time.Since(confObj.LastPush) > confObj.DBInterval + confObj.Mu.RLock() + answer := time.Since(confObj.LastPush) > confObj.DBInterval + confObj.Mu.RUnlock() + + return answer } // Launched by init as a coroutine to watch @@ -38,6 +46,7 @@ func cacheAndPush() { func refreshCache() { + twtxtCache.Mu.RLock() for k := range twtxtCache.Users { err := twtxtCache.UpdateUser(k) if err != nil { @@ -45,6 +54,7 @@ func refreshCache() { continue } } + twtxtCache.Mu.RUnlock() remoteRegistries.Mu.RLock() for _, v := range remoteRegistries.List { |