@@ -23,6 +23,8 @@ type CLI struct {
2323
2424 URL string `help:"Remote cache server URL." default:"http://127.0.0.1:8080"`
2525 Platform bool `help:"Prefix keys with platform ($${os}-$${arch}-)."`
26+ Daily bool `help:"Prefix keys with date ($${YYYY}-$${MM}-$${DD}-). Mutually exclusive with --hourly." xor:"timeprefix"`
27+ Hourly bool `help:"Prefix keys with date and hour ($${YYYY}-$${MM}-$${DD}-$${HH}-). Mutually exclusive with --daily." xor:"timeprefix"`
2628
2729 Get GetCmd `cmd:"" help:"Download object from cache." group:"Operations:"`
2830 Stat StatCmd `cmd:"" help:"Show metadata for cached object." group:"Operations:"`
@@ -194,9 +196,25 @@ func (pk *PlatformKey) String() string {
194196}
195197
196198func (pk * PlatformKey ) AfterApply (cli * CLI ) error {
197- if ! cli .Platform {
198- return nil
199+ prefixed := pk .raw
200+
201+ // Apply platform prefix if enabled
202+ if cli .Platform {
203+ prefixed = fmt .Sprintf ("%s-%s-%s" , runtime .GOOS , runtime .GOARCH , prefixed )
204+ }
205+
206+ // Apply time-based prefix if enabled (goes first in final order)
207+ now := time .Now ()
208+ if cli .Hourly {
209+ prefixed = now .Format ("2006-01-02-15-" ) + prefixed
210+ } else if cli .Daily {
211+ prefixed = now .Format ("2006-01-02-" ) + prefixed
199212 }
200- prefixed := fmt .Sprintf ("%s-%s-%s" , runtime .GOOS , runtime .GOARCH , pk .raw )
213+
214+ // Only print debug if we actually modified the key
215+ if prefixed != pk .raw {
216+ fmt .Fprintf (os .Stderr , "[DEBUG] Key transform: %s -> %s\n " , pk .raw , prefixed ) //nolint:forbidigo
217+ }
218+
201219 return errors .WithStack (pk .key .UnmarshalText ([]byte (prefixed )))
202220}
0 commit comments