-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.go
More file actions
30 lines (24 loc) · 766 Bytes
/
init.go
File metadata and controls
30 lines (24 loc) · 766 Bytes
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
package jcache
import (
"math/rand"
"time"
)
/**
@author : Jerbe - The porter from Earth
@time : 2023/8/28 13:00
@describe :
*/
const (
// KeepTTL 保持原先的过期时间(TTL)
KeepTTL = -1
// DefaultEmptySetNXDuration 默认空对象设置过期时效
DefaultEmptySetNXDuration = time.Second * 10
// DefaultExpirationDuration 默认缓存过期时效
DefaultExpirationDuration = time.Hour
)
// RandomExpirationDuration 以 DefaultExpirationDuration 为基础,返回一个 DefaultExpirationDuration ± 30m 内的时间长度
func RandomExpirationDuration() time.Duration {
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
r := (1 - rnd.Int63n(2)) * rnd.Int63n(30)
return DefaultExpirationDuration + (time.Minute * time.Duration(r))
}