set data to storage or memory
(ctx context.Context, key string, it *item, exp time.Duration)
| 163 | |
| 164 | // set data to storage or memory |
| 165 | func (m *manager) set(ctx context.Context, key string, it *item, exp time.Duration) error { |
| 166 | if m.storage != nil { |
| 167 | raw, err := it.MarshalMsg(nil) |
| 168 | if err != nil { |
| 169 | m.release(it) |
| 170 | return fmt.Errorf("cache: failed to marshal key %q: %w", m.logKey(key), err) |
| 171 | } |
| 172 | if err := m.storage.SetWithContext(ctx, key, raw, exp); err != nil { |
| 173 | m.release(it) |
| 174 | return fmt.Errorf("cache: failed to store key %q: %w", m.logKey(key), err) |
| 175 | } |
| 176 | m.release(it) |
| 177 | return nil |
| 178 | } |
| 179 | |
| 180 | m.memory.Set(key, it, exp) |
| 181 | return nil |
| 182 | } |
| 183 | |
| 184 | // set data to storage or memory |
| 185 | func (m *manager) setRaw(ctx context.Context, key string, raw []byte, exp time.Duration) error { |