package cache import ( "fmt" "hash/fnv" "strconv" "time" ) type SqlKey struct { format string ttl time.Duration table string clause string args []any } func NewSQLKey(tName string, t time.Duration, clause string, args ...any) *SqlKey { h := fnv.New32a() _, _ = h.Write([]byte(tName)) return &SqlKey{ format: fmt.Sprintf("sql_%s_%s", strconv.Itoa(int(h.Sum32())), "%v"), ttl: t, table: tName, clause: clause, args: args, } } func (k *SqlKey) Table() string { return k.table } func (k *SqlKey) Clause() string { return k.clause } func (k *SqlKey) Args() []any { return k.args } func (k *SqlKey) TTL() time.Duration { return k.ttl } func (k *SqlKey) String() string { return fmt.Sprintf(k.format, k.args...) }