(ctx context.Context, params KVParams)
| 100 | } |
| 101 | |
| 102 | func (kv *KVOperator) setCache(ctx context.Context, params KVParams) { |
| 103 | if kv.cacheTTL < 0 { |
| 104 | return |
| 105 | } |
| 106 | |
| 107 | ttl := kv.cacheTTL |
| 108 | if ttl > 10 { |
| 109 | ttl += time.Duration(float64(ttl) * 0.1 * (1 - rand.Float64())) |
| 110 | } |
| 111 | |
| 112 | cacheKey := kv.getCacheKey(params) |
| 113 | if err := kv.data.Cache.SetString(ctx, cacheKey, params.Value, ttl); err != nil { |
| 114 | log.Warnf("cache set failed: %v, key: %s", err, cacheKey) |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | func (kv *KVOperator) getCache(ctx context.Context, params KVParams) (string, bool, error) { |
| 119 | if kv.cacheTTL < 0 { |
no test coverage detected