refactor: sliding expiration cache with cleanup task#389
Merged
Conversation
b69c4d4 to
0682fce
Compare
db605e8 to
083d56f
Compare
083d56f to
1544535
Compare
f0c5c4b to
ebf88d4
Compare
crystall-bitquill
approved these changes
Feb 12, 2025
joyc-bq
approved these changes
Feb 14, 2025
ebf88d4 to
c253e10
Compare
25f713d to
0ffe63c
Compare
crystall-bitquill
approved these changes
Mar 3, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Introduces a new class SlidingExpirationCacheWithCleanupTask that asynchronously cleans up the cache.
Description
Instead of cleaning up whenever we access the cache, SlidingExpirationCacheWithCleanupTask cleans up all items of the cache that have expired at the rate of cleanupIntervalNanos given in the constructor.
The cleanup task is only initialized after the first item has been added to the cache. This ensures that static caches can be declared and not used without starting an untracked asynchronous task.
The clear method is also made asynchronous, when it is called the cleanup task is aborted and all items in the cache are disposed of and cleared.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.