File tree Expand file tree Collapse file tree 1 file changed +23
-5
lines changed Expand file tree Collapse file tree 1 file changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -69,8 +69,28 @@ func (p *githubPlugin) FileContent(subpath string) ([]byte, error) {
69
69
if err != nil {
70
70
return nil , err
71
71
}
72
+
73
+ // Cache for 24 hours. Once we store the plugin in the lockfile, we
74
+ // should cache this indefinitely and only invalidate if the plugin
75
+ // is updated.
76
+ ttl := 24 * time .Hour
77
+
78
+ // This is a stopgap until plugin is stored in lockfile.
79
+ // DEVBOX_X indicates this is an experimental env var.
80
+ // Use DEVBOX_X_GITHUB_PLUGIN_CACHE_TTL to override the default TTL.
81
+ // e.g. DEVBOX_X_GITHUB_PLUGIN_CACHE_TTL=1h will cache the plugin for 1 hour.
82
+ // Note: If you want to disable cache, we recommend using a low second value instead of zero to
83
+ // ensure only one network request is made.
84
+ ttlStr := os .Getenv ("DEVBOX_X_GITHUB_PLUGIN_CACHE_TTL" )
85
+ if ttlStr != "" {
86
+ ttl , err = time .ParseDuration (ttlStr )
87
+ if err != nil {
88
+ return nil , err
89
+ }
90
+ }
91
+
72
92
return githubCache .GetOrSet (
73
- contentURL ,
93
+ contentURL + ttlStr ,
74
94
func () ([]byte , time.Duration , error ) {
75
95
req , err := p .request (contentURL )
76
96
if err != nil {
@@ -96,10 +116,8 @@ func (p *githubPlugin) FileContent(subpath string) ([]byte, error) {
96
116
if err != nil {
97
117
return nil , 0 , err
98
118
}
99
- // Cache for 24 hours. Once we store the plugin in the lockfile, we
100
- // should cache this indefinitely and only invalidate if the plugin
101
- // is updated.
102
- return body , 24 * time .Hour , nil
119
+
120
+ return body , ttl , nil
103
121
},
104
122
)
105
123
}
You can’t perform that action at this time.
0 commit comments