8000 Introduce a DelayManager that lets us expire and refresh elements by andrewaylett · Pull Request #99 · andrewaylett/arc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Introduce a DelayManager that lets us expire and refresh elements #99

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

Merged
merged 1 commit into from
May 28, 2025

Conversation

andrewaylett
Copy link
Owner

No description provided.

@Copilot Copilot AI review requested due to automatic review settings May 28, 2025 20:54
Copy link
  • Surviving mutants in this change: 42
  • Killed mutants in this change: 35
class surviving killed
🧟eu.aylett.arc.internal.Element 17 14
🧟eu.aylett.arc.internal.DelayedElement 15 4
🧟eu.aylett.arc.Arc 5 5
🧟eu.aylett.arc.internal.DelayManager 3 8
🧟eu.aylett.arc.internal.ElementList 2 0
💯eu.aylett.arc.internal.InnerArc 0 4

See https://pitest.org

Copy link
@Copilot 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 adds a new DelayManager to schedule expiration and optional refresh of cached elements, updates the core cache implementation to use it, and extends the public Arc API to allow configuring expiry/refresh durations.

  • Introduce DelayManager and DelayedElement to track element lifetimes.
  • Refactor InnerArc, ElementList, Element, and Arc to integrate expiry and refresh logic.
  • Expand ArcTest with a repeatedElementsAreRefreshed test and MockInstantSource to verify timing behavior.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lib/src/test/java/eu/aylett/arc/ArcTest.java Added timing-based test case (repeatedElementsAreRefreshed) and MockInstantSource.
lib/src/main/java/eu/aylett/arc/internal/InnerArc.java Inject DelayManager, refactor constructors, processElement, and enqueueNewElement.
lib/src/main/java/eu/aylett/arc/internal/ElementList.java Replace name string with Name enum, preload values for expiring lists in push.
lib/src/main/java/eu/aylett/arc/internal/Element.java Refactor get/load, add delayExpired, reload, and integrate DelayManager.
lib/src/main/java/eu/aylett/arc/internal/DelayedElement.java New class representing a Delayed wrapper for expiry and refresh hooks.
lib/src/main/java/eu/aylett/arc/internal/DelayManager.java New class managing two DelayQueues: one for expiry and one for early refresh.
lib/src/main/java/eu/aylett/arc/Arc.java Update public API to accept expiry and refresh durations, add validation in constructors.
Comments suppressed due to low confidence (2)

lib/src/main/java/eu/aylett/arc/internal/DelayManager.java:66

  • [nitpick] The interface name GetDelay is vague; consider renaming it to DelayCalculator or DelayProvider to better convey its purpose.
public interface GetDelay {

lib/src/main/java/eu/aylett/arc/Arc.java:70

  • The removal of the simple two-argument Arc constructor is a breaking change for existing clients; consider reintroducing or deprecating the old overload to maintain backwards compatibility.
public Arc(int capacity, Function<K, V> loader, Duration expiry, Duration refresh) {

@@ -108,7 +115,7 @@ public InnerArc(int capacity, boolean safetyChecks) {
*/
@ReleasesNoLocks
@Holding("this")
public CompletableFuture<V> processElement(@GuardSatisfied InnerArc<K, V> this, Element<K, V> e) {
public CompletableFuture<V> processElement(@GuardedBy InnerArc<K, V> this, Element<?, V> e) {
Copy link
Preview
Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

The lock annotation on the receiver is inconsistent with the @GuardSatisfied annotation used elsewhere; consider using a consistent annotation to clarify the intended lock contract.

Suggested change
public CompletableFuture<V> processElement(@GuardedBy InnerArc<K, V> this, Element<?, V> e) {
public CompletableFuture<V> processElement(Element<?, V> e) {

Copilot uses AI. Check for mistakes.

Comment on lines +127 to +128
if (expiryTarget != null && !newElement.containsValue()) {
newElement.get();
Copy link
Preview
Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

Calling newElement.get() inside push may block the calling thread under lock and impact throughput; consider loading asynchronously or off the critical path.

Suggested change
if (expiryTarget != null && !newElement.containsValue()) {
newElement.get();
Object preloadedValue = null;
if (expiryTarget != null && !newElement.containsValue()) {
preloadedValue = newElement.get();

Copilot uses AI. Check for mistakes.

var record = recordedValues.stream().collect(Collectors.groupingBy((v) -> v, Collectors.counting()));
// Would be 100 without any caching or refreshing
assertThat(record.get(0), lessThan(50L));
// Would be ~15 with no early refreshes
Copy link
Preview
Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

[nitpick] The comment suggests an expected count of ~15, but the assertion checks greaterThan(25L); please align the comment with the actual assertion thresholds to avoid confusion.

Copilot uses AI. Check for mistakes.

@andrewaylett andrewaylett merged commit 9572174 into main May 28, 2025
6 checks passed
@andrewaylett andrewaylett deleted the push-lkvxqnvzwrwk branch May 28, 2025 21:03
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.

1 participant
0