addToBucket adds entry to expire bucket so that it will be cleaned up when the time comes. Has to be called with lock!
(e *Entry[K, V])
| 340 | |
| 341 | // addToBucket adds entry to expire bucket so that it will be cleaned up when the time comes. Has to be called with lock! |
| 342 | func (c *LRU[K, V]) addToBucket(e *Entry[K, V]) { |
| 343 | bucketID := (numBuckets + c.nextCleanupBucket - 1) % numBuckets |
| 344 | e.ExpireBucket = bucketID |
| 345 | c.buckets[bucketID].entries[e.Key] = e |
| 346 | if c.buckets[bucketID].newestEntry.Before(e.ExpiresAt) { |
| 347 | c.buckets[bucketID].newestEntry = e.ExpiresAt |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | // removeFromBucket removes the entry from its corresponding bucket. Has to be called with lock! |
| 352 | func (c *LRU[K, V]) removeFromBucket(e *Entry[K, V]) { |