-
Notifications
You must be signed in to change notification settings - Fork 19
/
cache.go
40 lines (34 loc) · 873 Bytes
/
cache.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package dockerconfig
import (
"sync"
"github.com/open-component-model/ocm/pkg/contexts/credentials/cpi"
"github.com/open-component-model/ocm/pkg/contexts/datacontext"
)
const ATTR_REPOS = "github.com/open-component-model/ocm/pkg/contexts/credentials/repositories/dockerconfig"
type Repositories struct {
lock sync.Mutex
repos map[string]*Repository
}
func newRepositories(datacontext.Context) interface{} {
return &Repositories{
repos: map[string]*Repository{},
}
}
func (r *Repositories) GetRepository(ctx cpi.Context, name string, data []byte, propagate bool) (*Repository, error) {
r.lock.Lock()
defer r.lock.Unlock()
var (
err error = nil
repo *Repository
)
if name != "" {
repo = r.repos[name]
}
if repo == nil {
repo, err = NewRepository(ctx, name, data, propagate)
if err == nil {
r.repos[name] = repo
}
}
return repo, err
}