-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
The expiration time can now be customized on a per entry basis to allow them to expire at different rates. This is acheived in O(1) time using a timer wheel and evaluating using the new Expiry interface. This setting can be combined with refreshAfterWrite, but is incompatible with the fixed expiration types (expireAfterAccess, expireAfterWrite). While the test suite was updated to incorporate this new configuration option, there is still remaining work before this should be released. - New tests specific to this feature (such as exceptional conditions) have not yet been written - Incorporate a data integrity check for the timer wheel into the validation listener - Inspection through cache.policy() - JCache integration - Documentation
- Loading branch information
Showing
30 changed files
with
927 additions
and
378 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
* @author [email protected] (Ben Manes) | ||
*/ | ||
final class Async { | ||
static final long MAXIMUM_EXPIRY = (Long.MAX_VALUE >> 1); // 150 years | ||
|
||
private Async() {} | ||
|
||
|
@@ -111,4 +112,56 @@ Object writeReplace() { | |
return delegate; | ||
} | ||
} | ||
|
||
/** | ||
* An expiry for asynchronous computations. When the value is being loaded this expiry returns | ||
* {@code Long.MAX_VALUE} to indicate that the entry should not be evicted due to an expiry | ||
* constraint. If the value is computed successfully the entry must be reinserted so that the | ||
* expiration is updated and the expiration timeouts reflect the value once present. The value | ||
* maximum range is reserved to coordinate the asynchronous life cycle. | ||
*/ | ||
static final class AsyncExpiry<K, V> implements Expiry<K, CompletableFuture<V>>, Serializable { | ||
private static final long serialVersionUID = 1L; | ||
|
||
final Expiry<K, V> delegate; | ||
|
||
AsyncExpiry(Expiry<K, V> delegate) { | ||
this.delegate = requireNonNull(delegate); | ||
} | ||
|
||
@Override | ||
public long expireAfterCreate(K key, CompletableFuture<V> future, long currentTime) { | ||
if (isReady(future)) { | ||
long duration = delegate.expireAfterCreate(key, future.join(), currentTime); | ||
return Math.min(duration, MAXIMUM_EXPIRY); | ||
} | ||
return Long.MAX_VALUE; | ||
} | ||
|
||
@Override | ||
public long expireAfterUpdate(K key, CompletableFuture<V> future, | ||
long currentTime, long currentDuration) { | ||
if (isReady(future)) { | ||
long duration = (currentDuration > MAXIMUM_EXPIRY) | ||
? delegate.expireAfterCreate(key, future.join(), currentTime) | ||
: delegate.expireAfterUpdate(key, future.join(), currentDuration, currentTime); | ||
return Math.min(duration, MAXIMUM_EXPIRY); | ||
} | ||
return currentDuration; | ||
} | ||
|
||
@Override | ||
public long expireAfterRead(K key, CompletableFuture<V> future, | ||
long currentTime, long currentDuration) { | ||
if (isReady(future) && (currentDuration > MAXIMUM_EXPIRY)) { | ||
long duration = delegate.expireAfterRead(key, future.join(), currentDuration, currentTime); | ||
return Math.min(duration, MAXIMUM_EXPIRY); | ||
} | ||
return currentDuration; | ||
} | ||
|
||
Object writeReplace() { | ||
return delegate; | ||
} | ||
} | ||
} |
Oops, something went wrong.