| 123 | } |
| 124 | |
| 125 | func (l *LRUCache) Add(ctx context.Context, key string, value []byte, ttl time.Duration) error { |
| 126 | err := l.c.Add(ctx, key, value, ttl) |
| 127 | |
| 128 | // When a caller uses the Add method, the presence of absence of an entry in the cache |
| 129 | // has significance. In order to maintain the semantics of that, we only add an entry to |
| 130 | // the LRU when it was able to be successfully added to the shared cache. |
| 131 | if err == nil { |
| 132 | l.mtx.Lock() |
| 133 | defer l.mtx.Unlock() |
| 134 | |
| 135 | expires := time.Now().Add(ttl) |
| 136 | l.lru.Add(key, &Item{ |
| 137 | Data: value, |
| 138 | ExpiresAt: expires, |
| 139 | }) |
| 140 | } |
| 141 | |
| 142 | return err |
| 143 | } |
| 144 | |
| 145 | func (l *LRUCache) GetMulti(ctx context.Context, keys []string, opts ...Option) (result map[string][]byte) { |
| 146 | result, err := l.GetMultiWithError(ctx, keys, opts...) |