-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapi_context_cache_content.go
59 lines (47 loc) · 1.45 KB
/
api_context_cache_content.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package moonshot
import (
"fmt"
"strings"
)
const (
ResetTTLNever = -1 // ResetTTLNever is the value for never reset ttl
ResetTTLImmediate = 0 // ResetTTLImmediate is the value for immediate reset ttl
)
// ContextCacheContent is the content for the context cache
type ContextCacheContent struct {
CacheId string `json:"cache_id"`
Tag string `json:"tag"`
ResetTTL int64 `json:"reset_ttl"`
DryRun bool `json:"dry_run"`
}
func NewContextCacheContentWithId(cacheId string) *ContextCacheContent {
return &ContextCacheContent{CacheId: cacheId, ResetTTL: ResetTTLNever}
}
func NewContextCacheContentWithTag(tag string) *ContextCacheContent {
return &ContextCacheContent{Tag: tag, ResetTTL: ResetTTLNever}
}
// WithResetTTL set the reset ttl for the context cache
func (c *ContextCacheContent) WithResetTTL(resetTTL int64) *ContextCacheContent {
c.ResetTTL = resetTTL
return c
}
// WithDryRun set the dry run for the context cache
func (c *ContextCacheContent) WithDryRun(dryRun bool) *ContextCacheContent {
c.DryRun = dryRun
return c
}
func (c *ContextCacheContent) Content() string {
var slice []string
if c.CacheId != "" {
slice = append(slice, fmt.Sprintf("cache_id=%s", c.CacheId))
} else if c.Tag != "" {
slice = append(slice, fmt.Sprintf("tag=%s", c.Tag))
}
if c.ResetTTL >= 0 {
slice = append(slice, fmt.Sprintf("reset_ttl=%d", c.ResetTTL))
}
if c.DryRun {
slice = append(slice, "dry_run=1")
}
return strings.Join(slice, ";")
}