mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
add sync.RWMutex to listCache
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
type DBReadCache struct {
|
type DBReadCache struct {
|
||||||
db TorrServerDB
|
db TorrServerDB
|
||||||
listCache map[string][]string
|
listCache map[string][]string
|
||||||
|
listCacheMutex sync.RWMutex
|
||||||
dataCache map[[2]string][]byte
|
dataCache map[[2]string][]byte
|
||||||
dataCacheMutex sync.RWMutex
|
dataCacheMutex sync.RWMutex
|
||||||
}
|
}
|
||||||
@@ -57,11 +58,16 @@ func (v *DBReadCache) Set(xPath, name string, value []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *DBReadCache) List(xPath string) []string {
|
func (v *DBReadCache) List(xPath string) []string {
|
||||||
|
v.listCacheMutex.RLock()
|
||||||
if names, ok := v.listCache[xPath]; ok {
|
if names, ok := v.listCache[xPath]; ok {
|
||||||
|
defer v.listCacheMutex.RUnlock()
|
||||||
return names
|
return names
|
||||||
}
|
}
|
||||||
|
v.listCacheMutex.RUnlock()
|
||||||
names := v.db.List(xPath)
|
names := v.db.List(xPath)
|
||||||
|
v.listCacheMutex.Lock()
|
||||||
v.listCache[xPath] = names
|
v.listCache[xPath] = names
|
||||||
|
v.listCacheMutex.Unlock()
|
||||||
return names
|
return names
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user