| 1327 | } |
| 1328 | |
| 1329 | func (r *Ring) setCachedShuffledSubring(identifier string, size int, subring *Ring) { |
| 1330 | if subring == nil || r.cfg.SubringCacheDisabled { |
| 1331 | return |
| 1332 | } |
| 1333 | |
| 1334 | r.mtx.Lock() |
| 1335 | defer r.mtx.Unlock() |
| 1336 | |
| 1337 | // Only cache if *this* ring hasn't changed since computing result |
| 1338 | // (which can happen between releasing the read lock and getting read-write lock). |
| 1339 | // Note that shuffledSubringCache can be only nil when set by test. |
| 1340 | if r.shuffledSubringCache != nil && r.lastTopologyChange.Equal(subring.lastTopologyChange) { |
| 1341 | r.shuffledSubringCache[subringCacheKey{identifier: identifier, shardSize: size}] = subring |
| 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | func (r *Ring) getCachedShuffledSubringWithLookback(identifier string, size int, lookbackPeriod time.Duration, now time.Time) *Ring { |
| 1346 | if r.cfg.SubringCacheDisabled { |