Skip to content

Commit

Permalink
perf[cache]: checkMaxSize need currentTimeMillis method for precise time
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Mar 27, 2024
1 parent b0a53b7 commit c4812dc
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class LazyCache<K, V> {

private static final float DEFAULT_BACK_PRESSURE_FACTOR = 0.11f;
private static final long MILLIS_MAX_SIZE_CHECK_INTERVAL = 300;
private static final long MILLIS_MAX_SIZE_CHECK_INTERVAL = 13;

private static class CacheValue<V> {
public volatile V value;
Expand Down Expand Up @@ -134,7 +134,7 @@ public int size() {
// -----------------------------------------------------------------------------------------------------------------
private void checkMaximumSize() {
if (cacheMap.size() > backPressureSize) {
var now = TimeUtils.now();
var now = TimeUtils.currentTimeMillis();
var sizeCheckTime = sizeCheckTimeAtomic.get();
if (now > sizeCheckTime) {
if (sizeCheckTimeAtomic.compareAndSet(sizeCheckTime, now + MILLIS_MAX_SIZE_CHECK_INTERVAL)) {
Expand Down

0 comments on commit c4812dc

Please sign in to comment.