1
0
out-of-tree/distro/debian/cache.go

47 lines
805 B
Go
Raw Normal View History

2023-05-11 18:45:44 +00:00
package debian
import (
2023-05-13 18:49:11 +00:00
"sync"
2023-05-11 18:45:44 +00:00
"github.com/rapidloop/skv"
)
type Cache struct {
store *skv.KVStore
}
2023-05-13 18:49:11 +00:00
// cache is not thread-safe, so make sure there are only one user
var mu sync.Mutex
2023-05-11 18:45:44 +00:00
func NewCache(path string) (c *Cache, err error) {
2023-05-13 18:49:11 +00:00
mu.Lock()
2023-05-11 18:45:44 +00:00
c = &Cache{}
c.store, err = skv.Open(path)
return
}
2023-05-11 19:26:54 +00:00
func (c Cache) Put(p DebianKernel) error {
return c.store.Put(p.Version.Package, p)
2023-05-11 18:45:44 +00:00
}
2023-05-11 19:26:54 +00:00
func (c Cache) Get(version string) (p DebianKernel, err error) {
2023-05-11 18:45:44 +00:00
err = c.store.Get(version, &p)
return
}
2023-05-13 18:43:15 +00:00
func (c Cache) PutVersions(versions []string) error {
return c.store.Put("versions", versions)
}
func (c Cache) GetVersions() (versions []string, err error) {
err = c.store.Get("versions", &versions)
return
}
2023-05-13 18:49:11 +00:00
func (c Cache) Close() (err error) {
err = c.store.Close()
mu.Unlock()
return
2023-05-11 18:45:44 +00:00
}