Skip to content

Commit

Permalink
fix: SlidingExpirationCache#put cache item expiration (#1203)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronchung-bitquill authored Nov 27, 2024
1 parent 5fc5d6c commit f811999
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ public void run() {

limitlessRouterCache.put(
this.limitlessRouterCacheKey,
newLimitlessRouters, LimitlessRouterServiceImpl.MONITOR_DISPOSAL_TIME_MS.getLong(props));
newLimitlessRouters,
TimeUnit.MILLISECONDS.toNanos(LimitlessRouterServiceImpl.MONITOR_DISPOSAL_TIME_MS.getLong(props)));

RoundRobinHostSelector.setRoundRobinHostWeightPairsProperty(this.props, newLimitlessRouters);
LOGGER.finest(Utils.logTopology(newLimitlessRouters, "[limitlessRouterMonitor] Topology:"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ protected void synchronouslyGetLimitlessRouters(final LimitlessConnectionContext
context.setLimitlessRouters(newLimitlessRouters);
limitlessRouterCache.put(
this.pluginService.getHostListProvider().getClusterId(),
newLimitlessRouters, LimitlessRouterServiceImpl.MONITOR_DISPOSAL_TIME_MS.getLong(context.getProps()));
newLimitlessRouters,
TimeUnit.MILLISECONDS.toNanos(
LimitlessRouterServiceImpl.MONITOR_DISPOSAL_TIME_MS.getLong(context.getProps())));
} else {
throw new SQLException(Messages.get("LimitlessRouterServiceImpl.fetchedEmptyRouterList"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ public V put(
final V value,
final long itemExpirationNano) {
cleanUp();
final CacheItem cacheItem = cache.put(key, new CacheItem(value, itemExpirationNano));
final CacheItem cacheItem = cache.put(key, new CacheItem(value, System.nanoTime() + itemExpirationNano));
if (cacheItem == null) {
return null;
}
return cacheItem.item;
return cacheItem.withExtendExpiration(itemExpirationNano).item;
}

public V get(final K key, final long itemExpirationNano) {
Expand Down

0 comments on commit f811999

Please sign in to comment.