| 130 | } |
| 131 | |
| 132 | func (sto *Storage) touch(sb blob.SizedRef) { |
| 133 | key := sb.Ref.String() |
| 134 | |
| 135 | sto.mu.Lock() |
| 136 | defer sto.mu.Unlock() |
| 137 | |
| 138 | _, old := sto.lru.Get(key) |
| 139 | if !old { |
| 140 | sto.lru.Add(key, sb) |
| 141 | sto.cacheBytes += int64(sb.Size) |
| 142 | |
| 143 | // Clean while needed. |
| 144 | for sto.cacheBytes > sto.maxCacheBytes { |
| 145 | if !sto.removeOldest() { |
| 146 | break |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | func (sto *Storage) Fetch(ctx context.Context, b blob.Ref) (rc io.ReadCloser, size uint32, err error) { |
| 153 | rc, size, err = sto.cache.Fetch(ctx, b) |