Store stores the key in the cache.
(ctx context.Context, keys []string, bufs [][]byte)
| 153 | |
| 154 | // Store stores the key in the cache. |
| 155 | func (c *Memcached) Store(ctx context.Context, keys []string, bufs [][]byte) { |
| 156 | for i := range keys { |
| 157 | select { |
| 158 | case <-ctx.Done(): |
| 159 | return |
| 160 | default: |
| 161 | } |
| 162 | |
| 163 | err := measureRequest(ctx, "Memcache.Put", c.requestDuration, memcacheStatusCode, func(_ context.Context) error { |
| 164 | item := memcache.Item{ |
| 165 | Key: keys[i], |
| 166 | Value: bufs[i], |
| 167 | Expiration: int32(c.cfg.Expiration.Seconds()), |
| 168 | } |
| 169 | return c.memcache.Set(&item) |
| 170 | }) |
| 171 | if err != nil { |
| 172 | level.Error(c.logger).Log("msg", "failed to put to memcached", "name", c.name, "err", err) |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | func (c *Memcached) Stop() { |
| 178 | c.memcache.Close() |