Skip to content

Caffeine for Caching#590

Merged
jakobvogel merged 8 commits intomainfrom
feature/jvo/SIRI-1175-Caffeinated-Caching
Jan 14, 2026
Merged

Caffeine for Caching#590
jakobvogel merged 8 commits intomainfrom
feature/jvo/SIRI-1175-Caffeinated-Caching

Conversation

@jakobvogel
Copy link
Member

@jakobvogel jakobvogel commented Jan 14, 2026

Description

Replaces Guava Caches with Caffeine.

Caution

After upgrading, the major breaking change is that cache.getLastEvictionRun() now returns an Instant rather than a Date. As Date should not be used anymore, the best solution is to upgrade the surrounding code to use the Java Time libraries as well. However, if that is not feasible, conversion to a Date as before can be done via Date.from(cache.getLastEvictionRun()).

The new caching library should not have changed the behaviour of the cache. Still, increased attention should be given to performance of code known to use caching.

Additional Notes

  • This PR fixes or works on following ticket(s): SIRI-1175

Checklist

  • Code change has been tested and works locally
  • Code was formatted via IntelliJ and follows SonarLint & best practices

@jakobvogel jakobvogel self-assigned this Jan 14, 2026
@jakobvogel jakobvogel added the 💣 BREAKING CHANGE Contains non-backwards compatible changes to public methods or changes the behavior of existing code label Jan 14, 2026
…as the cache actually contains cache entries that have additional information.

SIRI-1175
…in order to safe unchecked casts.

SIRI-1175
@jakobvogel jakobvogel requested a review from Copilot January 14, 2026 15:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates the caching implementation from Guava Cache to Caffeine, a more performant drop-in replacement.

Changes:

  • Replaced Guava Cache imports and API calls with Caffeine equivalents throughout the cache implementation
  • Updated return type from Date to Instant for getLastEvictionRun() method
  • Added comprehensive test coverage for the removal listener functionality

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
pom.xml Added Caffeine 3.2.3 dependency as replacement for Guava Cache
src/main/java/sirius/kernel/cache/Cache.java Updated interface to use Instant instead of Date for eviction timestamp
src/main/java/sirius/kernel/cache/ManagedCache.java Replaced Guava Cache with Caffeine, including API changes for cache building, removal listeners, and size estimation
src/test/kotlin/sirius/kernel/cache/ManagedCacheTest.kt Corrected class documentation and added test for removal listener invocation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

cache.put("key1", "value1")
cache.remove("key1")

Wait.millis(1001)
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The hardcoded 1001ms wait is excessive and will slow down test execution. Since removal listeners in Caffeine are invoked synchronously during removal operations, this wait should not be necessary. Consider removing this wait or reducing it significantly if there's a specific asynchronous behavior being tested.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Reicht hier ein @NightlyTest? Oder bekommt man das Wait sogar weg?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ich habe die Wartezeit reduziert auf eine Zehntelsekunde. Ich würde den Test schon ganz gerne belassen.

@jakobvogel jakobvogel merged commit 47af6f9 into main Jan 14, 2026
4 checks passed
@jakobvogel jakobvogel deleted the feature/jvo/SIRI-1175-Caffeinated-Caching branch January 14, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💣 BREAKING CHANGE Contains non-backwards compatible changes to public methods or changes the behavior of existing code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants