Set data
(_ context.Context, key string, val interface{}, expiration time.Duration)
| 130 | |
| 131 | // Set data |
| 132 | func (m *memoryCache) Set(_ context.Context, key string, val interface{}, expiration time.Duration) error { |
| 133 | buf, err := encoding.Marshal(m.encoding, val) |
| 134 | if err != nil { |
| 135 | return fmt.Errorf("encoding.Marshal error: %v, key=%s, val=%+v ", err, key, val) |
| 136 | } |
| 137 | if len(buf) == 0 { |
| 138 | buf = NotFoundPlaceholderBytes |
| 139 | } |
| 140 | cacheKey, err := BuildCacheKey(m.KeyPrefix, key) |
| 141 | if err != nil { |
| 142 | return fmt.Errorf("BuildCacheKey error: %v, key=%s", err, key) |
| 143 | } |
| 144 | ok := m.client.SetWithTTL(cacheKey, buf, 0, expiration) |
| 145 | if !ok { |
| 146 | return errors.New("SetWithTTL failed") |
| 147 | } |
| 148 | m.client.Wait() |
| 149 | |
| 150 | return nil |
| 151 | } |
| 152 | |
| 153 | // Get data |
| 154 | func (m *memoryCache) Get(_ context.Context, key string, val interface{}) error { |
no test coverage detected