Skip to content

Conversation

@bitfaster
Copy link
Owner

@bitfaster bitfaster commented Nov 7, 2023

When items are touched, they are moved to warm by cycling. The Clear() logic naively attempted to cycle the queues n times, where n is the number of items in the cache. Any items that were touched would be cycled to warm, and would fail to be removed.

Fix summary:

  • Consolidate Clear() logic to call into TrimLiveItems(), which tracks how many items have been removed.
  • All hot and warm items can cycle into warm. Therefore, to guarantee that we can remove itemCount items, we must cycle capacity.Warm + capacity.Hot times. Fixed TrimLiveItems() to take this into account.
  • Implemented unit tests for Trim() and Clear() that verify touched items are removed correctly.

@bitfaster bitfaster linked an issue Nov 7, 2023 that may be closed by this pull request
@coveralls
Copy link

coveralls commented Nov 7, 2023

Coverage Status

coverage: 98.493% (-0.07%) from 98.56%
when pulling 6f2dfb0 on users/alexpeck/lruclear
into dbb6d7b on main.

@bitfaster bitfaster merged commit 175e9d5 into main Nov 7, 2023
@bitfaster bitfaster deleted the users/alexpeck/lruclear branch November 7, 2023 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cache.Clear() doesn't seem to be clearing entire cache

3 participants