@@ -3,41 +3,52 @@ package oldcache
33import (
44 "strings"
55
6+ "github.com/bitrise-io/go-steputils/v2/stepenv"
67 "github.com/bitrise-io/go-utils/v2/env"
78)
89
9- // CacheIncludePathsEnvKey .. .
10+ // CacheIncludePathsEnvKey's value is a newline separated list of paths that should be included in the cache .
1011const CacheIncludePathsEnvKey = "BITRISE_CACHE_INCLUDE_PATHS"
1112
12- // CacheExcludePathsEnvKey .. .
13+ // CacheExcludePathsEnvKey's value is a newline separated list of paths that should be excluded from the cache .
1314const CacheExcludePathsEnvKey = "BITRISE_CACHE_EXCLUDE_PATHS"
1415
15- // Cache ...
16- type Cache struct {
16+ // Cache is an interface for managing cache paths.
17+ type Cache interface {
18+ IncludePath (item ... string )
19+ ExcludePath (item ... string )
20+ Commit () error
21+ }
22+
23+ type cache struct {
1724 envRepository env.Repository
1825
1926 include []string
2027 exclude []string
2128}
2229
23- // New ...
30+ // NewDefault creates a new Cache instance that set envs using envman.
31+ func NewDefault () Cache {
32+ return New (stepenv .NewRepository (env .NewRepository ()))
33+ }
34+
35+ // New creates a new Cache instance with a custom env.Repository.
2436func New (envRepository env.Repository ) Cache {
25- // defaultConfig := Config{NewOSVariableGetter(), []VariableSetter{NewOSVariableSetter(), NewEnvmanVariableSetter()}}
26- return Cache {envRepository : envRepository }
37+ return & cache {envRepository : envRepository }
2738}
2839
29- // IncludePath .. .
30- func (cache * Cache ) IncludePath (item ... string ) {
40+ // IncludePath appends paths to the cache include list .
41+ func (cache * cache ) IncludePath (item ... string ) {
3142 cache .include = append (cache .include , item ... )
3243}
3344
34- // ExcludePath .. .
35- func (cache * Cache ) ExcludePath (item ... string ) {
45+ // ExcludePath appends paths to the cache exclude list .
46+ func (cache * cache ) ExcludePath (item ... string ) {
3647 cache .exclude = append (cache .exclude , item ... )
3748}
3849
39- // Commit .. .
40- func (cache * Cache ) Commit () error {
50+ // Commit writes paths to environment variables (also exported by envman when using stepenv.Repository) .
51+ func (cache * cache ) Commit () error {
4152 commitCachePath := func (key string , values []string ) error {
4253 content := cache .envRepository .Get (key )
4354 if content != "" {
0 commit comments