Fix concurrent map writes for FeedIcon cache

This commit is contained in:
quoing 2022-06-21 09:39:06 +02:00 committed by nkanaev
parent 286cbff236
commit a8d160f9b1
2 changed files with 5 additions and 0 deletions

View File

@ -177,7 +177,9 @@ func (s *Server) handleFeedIcon(c *router.Context) {
bytes: *(*feed).Icon, bytes: *(*feed).Icon,
etag: etag, etag: etag,
} }
s.cache_mutex.Lock()
s.cache[cachekey] = cachedat s.cache[cachekey] = cachedat
s.cache_mutex.Unlock()
} }
icon := cachedat.(feedicon) icon := cachedat.(feedicon)

View File

@ -3,6 +3,7 @@ package server
import ( import (
"log" "log"
"net/http" "net/http"
"sync"
"github.com/nkanaev/yarr/src/storage" "github.com/nkanaev/yarr/src/storage"
"github.com/nkanaev/yarr/src/worker" "github.com/nkanaev/yarr/src/worker"
@ -13,6 +14,7 @@ type Server struct {
db *storage.Storage db *storage.Storage
worker *worker.Worker worker *worker.Worker
cache map[string]interface{} cache map[string]interface{}
cache_mutex *sync.Mutex
BasePath string BasePath string
@ -30,6 +32,7 @@ func NewServer(db *storage.Storage, addr string) *Server {
Addr: addr, Addr: addr,
worker: worker.NewWorker(db), worker: worker.NewWorker(db),
cache: make(map[string]interface{}), cache: make(map[string]interface{}),
cache_mutex: &sync.Mutex{},
} }
} }