diff options
author | Ben Morrison <ben@gbmor.dev> | 2019-06-06 16:07:53 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2019-06-08 02:29:20 -0400 |
commit | e9d4a6b0e8624c6425d467f0efe14be1bc683bd9 (patch) | |
tree | 02b928c2c8fe28153980e6612c3349104091c083 /svc/cache.go | |
parent | 6749dc4d215dd60900f0c1187ba20031ccdc4f85 (diff) | |
download | getwtxt-e9d4a6b0e8624c6425d467f0efe14be1bc683bd9.tar.gz |
database refs and static assets concurrency-safe
Diffstat (limited to 'svc/cache.go')
-rw-r--r-- | svc/cache.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/svc/cache.go b/svc/cache.go index db427db..6b50a0e 100644 --- a/svc/cache.go +++ b/svc/cache.go @@ -18,6 +18,7 @@ type RemoteRegistries struct { } type staticAssets struct { + mu sync.RWMutex index []byte indexMod time.Time css []byte @@ -98,8 +99,10 @@ func pingAssets() { log.Printf("%v\n", err.Error()) } + staticCache.mu.RLock() indexMod := staticCache.indexMod cssMod := staticCache.cssMod + staticCache.mu.RUnlock() if !indexMod.Equal(indexStat.ModTime()) { tmpls = initTemplates() @@ -114,8 +117,10 @@ func pingAssets() { log.Printf("%v\n", err.Error()) } + staticCache.mu.Lock() staticCache.index = buf.Bytes() staticCache.indexMod = indexStat.ModTime() + staticCache.mu.Unlock() } if !cssMod.Equal(cssStat.ModTime()) { @@ -125,7 +130,9 @@ func pingAssets() { log.Printf("%v\n", err.Error()) } + staticCache.mu.Lock() staticCache.css = css staticCache.cssMod = cssStat.ModTime() + staticCache.mu.Unlock() } } |