| 33 | } |
| 34 | |
| 35 | func (cc *LocalCertCache) Get(ctx context.Context, key string) ([]byte, error) { |
| 36 | resItem, ok := cc.cache.GetValidOrDelete(key) |
| 37 | if !ok { |
| 38 | v, _, _ := cc.sf.Do(key, func() (any, error) { |
| 39 | res, err := cc.next.Get(ctx, key) |
| 40 | item := &certCacheValue{ |
| 41 | ts: time.Now(), |
| 42 | res: res, |
| 43 | err: err, |
| 44 | } |
| 45 | if ctx.Err() == nil { |
| 46 | cc.cache.Set(key, item) |
| 47 | } |
| 48 | return item, err |
| 49 | }) |
| 50 | resItem = v.(*certCacheValue) |
| 51 | } |
| 52 | return resItem.res, resItem.err |
| 53 | } |
| 54 | |
| 55 | func (cc *LocalCertCache) Put(ctx context.Context, key string, data []byte) error { |
| 56 | cc.cache.Set(key, &certCacheValue{ |