Skip to content

Commit 9760640

Browse files
refactor(registry): return default cache TTL by value (#296)
Return the default TTL without allocating a pointer, while preserving the existing Duration.String nil behavior at CLI call sites. Refs #174 Assisted-by: Codex (GPT-5) <noreply@openai.com>
1 parent 35b1872 commit 9760640

7 files changed

Lines changed: 29 additions & 8 deletions

File tree

cmd/add.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,11 @@ func NewAddCmd(baseCmd *internalcmd.BaseCmd, opt ...cmdopts.CmdOption) (*cobra.C
131131
"Directory for caching registry manifests",
132132
)
133133

134+
defaultCacheTTL := regopts.DefaultCacheTTL()
134135
cobraCommand.Flags().StringVar(
135136
&c.CacheTTL,
136137
"cache-ttl",
137-
regopts.DefaultCacheTTL().String(),
138+
defaultCacheTTL.String(),
138139
"Time-to-live for cached registry manifests (e.g. 1h, 30m, 24h)",
139140
)
140141

cmd/config/tools/list.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,11 @@ func NewListCmd(baseCmd *internalcmd.BaseCmd, opt ...cmdopts.CmdOption) (*cobra.
100100
"Directory for caching registry manifests",
101101
)
102102

103+
defaultCacheTTL := options.DefaultCacheTTL()
103104
cobraCmd.Flags().StringVar(
104105
&c.cacheTTL,
105106
"cache-ttl",
106-
options.DefaultCacheTTL().String(),
107+
defaultCacheTTL.String(),
107108
"Time-to-live for cached registry manifests (e.g. 1h, 30m, 24h)",
108109
)
109110

cmd/config/tools/set.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,11 @@ func NewSetCmd(baseCmd *cmd.BaseCmd, opt ...cmdopts.CmdOption) (*cobra.Command,
9191
"Directory for caching registry manifests",
9292
)
9393

94+
defaultCacheTTL := options.DefaultCacheTTL()
9495
cobraCmd.Flags().StringVar(
9596
&c.cacheTTL,
9697
"cache-ttl",
97-
options.DefaultCacheTTL().String(),
98+
defaultCacheTTL.String(),
9899
"Time-to-live for cached registry manifests (e.g. 1h, 30m, 24h)",
99100
)
100101

cmd/search.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,11 @@ func NewSearchCmd(baseCmd *internalcmd.BaseCmd, opt ...cmdopts.CmdOption) (*cobr
148148
"Directory for caching registry manifests",
149149
)
150150

151+
defaultCacheTTL := options.DefaultCacheTTL()
151152
cobraCommand.Flags().StringVar(
152153
&c.CacheTTL,
153154
"cache-ttl",
154-
options.DefaultCacheTTL().String(),
155+
defaultCacheTTL.String(),
155156
"Time-to-live for cached registry manifests (e.g. 1h, 30m, 24h)",
156157
)
157158

internal/cache/cache_options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func NewOptions(opts ...Option) (Options, error) {
3535
// Default options.
3636
o := Options{
3737
dir: dir,
38-
ttl: time.Duration(*options.DefaultCacheTTL()),
38+
ttl: time.Duration(options.DefaultCacheTTL()),
3939
enabled: true,
4040
refreshCache: false,
4141
}

internal/registry/options/build_options.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ func DefaultCacheDir() (string, error) {
9191
}
9292

9393
// DefaultCacheTTL returns the default cache time-to-live.
94-
func DefaultCacheTTL() *config.Duration {
95-
d := config.Duration(24 * time.Hour)
96-
return &d
94+
func DefaultCacheTTL() config.Duration {
95+
return config.Duration(24 * time.Hour)
9796
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package options
2+
3+
import (
4+
"testing"
5+
"time"
6+
7+
"github.com/stretchr/testify/require"
8+
9+
"github.com/mozilla-ai/mcpd/internal/config"
10+
)
11+
12+
func TestDefaultCacheTTL(t *testing.T) {
13+
t.Parallel()
14+
15+
ttl := DefaultCacheTTL()
16+
require.Equal(t, config.Duration(24*time.Hour), ttl)
17+
require.Equal(t, "24h", ttl.String())
18+
}

0 commit comments

Comments
 (0)