Add event when item is evicted #90
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Modify HitCounter to expose OnItemRemoved() and plumb into an event on ConcurrentLru/ConcurrentTLru. Event fires with a reason (either removed or evicted) whenever an item is removed. Event is invoked before value is disposed (if it is IDisposable).
Enables this code to be written:
LRU.GetOrAdd method total bytes of assembly code:
Fast (event omitted) 280 bytes
Event not registered: 306 bytes
Event registered: 306 bytes
Compared to main, GetOrAdd is increased from 302 to 306 bytes:
LRU.Move method total bytes of assembly code:
Fast (event omitted) 441 bytes
Event not registered: 508 bytes
Event registered: 508 bytes
Making the event have an empty body to avoid the null check (which is only possible in .NET 6 because it requires a struct field initializer), makes the code 503 bytes but then the event arg is always allocated even if there is no subscribed listener.