Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: SlidingExpirationCache and SlidingExpirationCacheWithCleanupThread #1142

Merged
merged 5 commits into from
Oct 8, 2024

Conversation

aaron-congo
Copy link
Contributor

@aaron-congo aaron-congo commented Oct 3, 2024

Summary

fix: SlidingExpirationCache and SlidingExpirationCacheWithCleanupThread

Description

Contains fixes for SlidingExpirationCache and SlidingExpirationCacheWithCleanupThread:

  • in SlidingExpirationCache, synchronized shouldCleanup check and subsequent removal from cache. This prevents the scenario where a cache item is grabbed after shouldCleanup() returns true but before its removed from the cache.
  • in SlidingExpirationCacheWithCleanupThread, some cleanup thread variables were static, which made it so that only one cache could create a cleanup thread. By removing the static keyword we ensure each cache has its own cleanup thread.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link

github-actions bot commented Oct 3, 2024

Qodana Community for JVM

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked

View the detailed Qodana report

To be able to view the detailed Qodana report, you can either:

  1. Register at Qodana Cloud and configure the action
  2. Use GitHub Code Scanning with Qodana
  3. Host Qodana report at GitHub Pages
  4. Inspect and use qodana.sarif.json (see the Qodana SARIF format for details)

To get *.log files or any other Qodana artifacts, run the action with upload-result option set to true,
so that the action will upload the files as the job artifacts:

      - name: 'Qodana Scan'
        uses: JetBrains/[email protected]
        with:
          upload-result: true
Contact Qodana team

Contact us at [email protected]

// A list is used to store the cached item for later disposal since lambdas require references to outer variables
// to be final. This allows us to dispose of the item after it has been removed and the cache has been unlocked,
// which is important because the disposal function may be long-running.
final List<V> itemList = new ArrayList<>(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you use List<> instead of a simple variable of type V?

Copy link
Contributor Author

@aaron-congo aaron-congo Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I try to do that I get "Variable used in lambda expression should be final or effectively final". It seems you cannot assign a value to a variable declared outside of the lambda unless that variable is final. The solutions my IDE proposes are other making it an atomic reference or making it a list. This relates to this discussion on the custom endpoint PR.

@aaron-congo aaron-congo merged commit 37a73b0 into main Oct 8, 2024
6 checks passed
@aaron-congo aaron-congo deleted the sliding-expiration-fixes branch October 8, 2024 21:36
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.

2 participants