12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package cache
- import (
- "fmt"
- "hash/fnv"
- "strconv"
- "time"
- )
- type SqlKey struct {
- format string
- ttl time.Duration
- table string
- selection []string
- clause string
- args []any
- }
- func NewSQLKey(tName string, t time.Duration, selection []string, clause string, args ...any) *SqlKey {
- h := fnv.New32a()
- _, _ = h.Write([]byte(tName))
- return &SqlKey{
- format: fmt.Sprintf("sql_%s_%s_%v", strconv.Itoa(int(h.Sum32())), "%v", selection),
- ttl: t,
- table: tName,
- selection: selection,
- clause: clause,
- args: args,
- }
- }
- func (k *SqlKey) Table() string {
- return k.table
- }
- func (k *SqlKey) Selection() []string {
- return k.selection
- }
- 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...)
- }
|