Skip to content

Conversation

imDMK
Copy link
Contributor

@imDMK imDMK commented Sep 30, 2025

Description

This PR refactors the delay handling to eliminate cache-level TTL conflicts.

  • Introduced GuavaDelay with shared logic on top of Guava Cache
  • Removed expireAfterWrite to ensure TTL is controlled per entry via Instant
  • Added separate interfaces: DefaultDelay (with predefined duration) and ExplicitDelay (explicit duration required)
  • Implemented GuavaDefaultDelay and GuavaExplicitDelay
  • Added Delay factory for convenient instance creation
  • Clarified contract and documentation

Result: cleaner API, safer usage, no premature cache evictions.
Fixes #1153

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Localhost server

@imDMK imDMK added 🔧 enhancement Enhances existing function 🔓 API labels Sep 30, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the delay system to use per-entry TTLs, which is a significant improvement for avoiding cache-level conflicts. The introduction of DefaultDelay and ExplicitDelay interfaces, along with a factory, creates a much cleaner and safer API. My review highlights a critical issue where expireAfterWrite was unintentionally reintroduced in GuavaDefaultDelay, undermining the primary goal of this refactoring. I have also included some suggestions to improve the API design by reducing code duplication and better aligning the interface documentation with its behavior, which would enhance flexibility and maintainability.

Copy link
Member

@P1otrulla P1otrulla left a comment

Choose a reason for hiding this comment

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

Good job i like it but i'm thinking about overenginering at this case - maybe Im wrong

@imDMK
Copy link
Contributor Author

imDMK commented Sep 30, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request provides a solid refactoring of the delay system, moving from a cache-level TTL to a per-entry TTL managed by Instant. This is a great improvement for correctness and prevents premature evictions. The introduction of DefaultDelay and ExplicitDelay interfaces, along with a factory class, results in a much cleaner and more robust API. The implementation is well-structured, especially the shared logic in GuavaDelay. I've identified a few minor inconsistencies in handling expiration edge cases that could be addressed to further improve the robustness of the new system. Overall, this is a high-quality contribution.

imDMK and others added 2 commits September 30, 2025 14:56
…Delay.java

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…Delay.java

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
….java

Co-authored-by: Igor Michalski <imichalsky00@gmail.com>
Copy link
Member

@Jakubk15 Jakubk15 left a comment

Choose a reason for hiding this comment

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

Looks solid to me. Shout-out for the good documentation of the API.

*
* @param <T> key type
*/
public interface DefaultDelay<T> extends ExplicitDelay<T> {
Copy link
Member

Choose a reason for hiding this comment

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

Rename to FixedDelay. Sounds better imo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔓 API 🔧 enhancement Enhances existing function
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[api] Delay always uses the expireAfterWrite duration time instead of the custom duration in the markDelay method.
5 participants