Skip to content

Commit 316046b

Browse files
committed
Make registry cache TTL configurable
1 parent 9e82d6a commit 316046b

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,14 @@ Config file: `~/.skrc`
158158
```json
159159
{
160160
"skills_dir": "~/.claude/skills",
161-
"registry": "https://raw.githubusercontent.com/majiayu000/claude-skill-registry/main"
161+
"registry": "https://raw.githubusercontent.com/majiayu000/claude-skill-registry/main",
162+
"registry_ttl_hours": 24
162163
}
163164
```
164165

165166
Registry cache:
166167
- Location: `~/.cache/sk/registry.json`
167-
- TTL: 24 hours (cache is ignored after expiry)
168+
- TTL: `registry_ttl_hours` (cache is ignored after expiry)
168169

169170
## Built With
170171

internal/config/config.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ import (
99

1010
// Config represents the global configuration
1111
type Config struct {
12-
SkillsDir string `json:"skills_dir"`
13-
Registry string `json:"registry"`
12+
SkillsDir string `json:"skills_dir"`
13+
Registry string `json:"registry"`
14+
RegistryTTLHours int `json:"registry_ttl_hours"`
1415
}
1516

1617
// DefaultConfig returns default configuration
1718
func DefaultConfig() *Config {
1819
homeDir, _ := os.UserHomeDir()
1920
return &Config{
20-
SkillsDir: filepath.Join(homeDir, ".claude", "skills"),
21-
Registry: "github",
21+
SkillsDir: filepath.Join(homeDir, ".claude", "skills"),
22+
Registry: "github",
23+
RegistryTTLHours: 24,
2224
}
2325
}
2426

@@ -28,6 +30,15 @@ func GetSkillsDir() string {
2830
return cfg.SkillsDir
2931
}
3032

33+
// GetRegistryTTL returns registry cache TTL in hours.
34+
func GetRegistryTTL() int {
35+
cfg := Load()
36+
if cfg.RegistryTTLHours <= 0 {
37+
return DefaultConfig().RegistryTTLHours
38+
}
39+
return cfg.RegistryTTLHours
40+
}
41+
3142
// GetRegistryBaseURL returns the registry base URL.
3243
// If config uses legacy "github", return default registry URL.
3344
func GetRegistryBaseURL() string {

internal/registry/registry.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
const (
1616
// DefaultRegistryURL is the base URL for the skill registry
1717
DefaultRegistryURL = "https://raw.githubusercontent.com/majiayu000/claude-skill-registry/main"
18-
registryCacheTTL = 24 * time.Hour
1918
)
2019

2120
// Registry represents the skill registry
@@ -239,7 +238,8 @@ func loadRegistryCache() (*Registry, error) {
239238
if err != nil {
240239
return nil, err
241240
}
242-
if time.Since(info.ModTime()) > registryCacheTTL {
241+
ttl := time.Duration(config.GetRegistryTTL()) * time.Hour
242+
if time.Since(info.ModTime()) > ttl {
243243
return nil, fmt.Errorf("registry cache expired")
244244
}
245245

0 commit comments

Comments
 (0)