mirror of https://github.com/databricks/cli.git
review comments
This commit is contained in:
parent
41313db1b2
commit
870003d2fc
|
@ -13,30 +13,30 @@ const cacheTTL = 1 * time.Hour
|
||||||
|
|
||||||
// NewReleaseCache creates a release cache for a repository in the GitHub org.
|
// NewReleaseCache creates a release cache for a repository in the GitHub org.
|
||||||
// Caller has to provide different cache directories for different repositories.
|
// Caller has to provide different cache directories for different repositories.
|
||||||
func NewReleaseCache(org, repo, cacheDir string) *ReleaseCache {
|
func NewReleaseCache(org, repo, cacheDir string, offlineInstall bool) *ReleaseCache {
|
||||||
pattern := fmt.Sprintf("%s-%s-releases", org, repo)
|
pattern := fmt.Sprintf("%s-%s-releases", org, repo)
|
||||||
return &ReleaseCache{
|
return &ReleaseCache{
|
||||||
Cache: localcache.NewLocalCache[Versions](cacheDir, pattern, cacheTTL),
|
cache: localcache.NewLocalCache[Versions](cacheDir, pattern, cacheTTL),
|
||||||
Org: org,
|
Org: org,
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
|
Offline: offlineInstall,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ReleaseCache struct {
|
type ReleaseCache struct {
|
||||||
Cache localcache.LocalCache[Versions]
|
cache localcache.LocalCache[Versions]
|
||||||
Org string
|
Org string
|
||||||
Repo string
|
Repo string
|
||||||
Offline bool
|
Offline bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ReleaseCache) Load(ctx context.Context) (Versions, error) {
|
func (r *ReleaseCache) Load(ctx context.Context) (Versions, error) {
|
||||||
return r.Cache.Load(ctx, func() (Versions, error) {
|
if !r.Offline {
|
||||||
|
return r.cache.Load(ctx, func() (Versions, error) {
|
||||||
return getVersions(ctx, r.Org, r.Repo)
|
return getVersions(ctx, r.Org, r.Repo)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
cached, err := r.cache.LoadCache()
|
||||||
func (r *ReleaseCache) LoadCache(ctx context.Context) (Versions, error) {
|
|
||||||
cached, err := r.Cache.LoadCache()
|
|
||||||
return cached.Data, err
|
return cached.Data, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue