1
0
Fork 0

feat: make sure of cache thread-safety

master
dump_stack() 2023-05-13 18:49:11 +00:00
parent 70fec57d2f
commit d0693e64c4
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
1 changed files with 11 additions and 2 deletions

View File

@ -1,6 +1,8 @@
package debian
import (
"sync"
"github.com/rapidloop/skv"
)
@ -8,7 +10,12 @@ type Cache struct {
store *skv.KVStore
}
// cache is not thread-safe, so make sure there are only one user
var mu sync.Mutex
func NewCache(path string) (c *Cache, err error) {
mu.Lock()
c = &Cache{}
c.store, err = skv.Open(path)
return
@ -32,6 +39,8 @@ func (c Cache) GetVersions() (versions []string, err error) {
return
}
func (c Cache) Close() error {
return c.store.Close()
func (c Cache) Close() (err error) {
err = c.store.Close()
mu.Unlock()
return
}