()
| 223 | } |
| 224 | |
| 225 | func (c *Cache) randomSleep() { |
| 226 | if c.Sequence == 0 { |
| 227 | return |
| 228 | } |
| 229 | // 生成 10-30 的随机数(对应 1.0-3.0 秒,粒度 0.1秒) |
| 230 | randomValue := rand.Intn(21) + 10 // 0-20 + 10 = 10-30 |
| 231 | // 转换为 Duration(乘以 0.1秒 = 100毫秒) |
| 232 | duration := time.Duration(randomValue) * 100 * time.Millisecond |
| 233 | time.Sleep(duration) |
| 234 | log.Infof("cache refresh sleep %s", duration.String(), c.metadata.LogPrefixes) |
| 235 | } |
| 236 | |
| 237 | // 所有缓存的刷新入口 |
| 238 | func (c *Cache) Refresh() { |