This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new 4d5158f fix expire cache time (#6480)
4d5158f is described below
commit 4d5158fcef4e446eb1c0de00f5a3aa4847d8de26
Author: Egg <[email protected]>
AuthorDate: Fri Mar 26 11:47:42 2021 +0800
fix expire cache time (#6480)
* fix expire cache time
* timeToLive > 0
Co-authored-by: changwenbo <[email protected]>
---
.../java/org/apache/dubbo/cache/support/expiring/ExpiringMap.java | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git
a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringMap.java
b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringMap.java
index 326b51e..b5306e2 100644
---
a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringMap.java
+++
b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringMap.java
@@ -84,6 +84,12 @@ public class ExpiringMap<K, V> implements Map<K, V> {
public V get(Object key) {
ExpiryObject object = delegateMap.get(key);
if (object != null) {
+ long timeIdle = System.currentTimeMillis() -
object.getLastAccessTime();
+ int timeToLive = expireThread.getTimeToLive();
+ if (timeToLive > 0 && timeIdle >= timeToLive * 1000) {
+ delegateMap.remove(object.getKey());
+ return null;
+ }
object.setLastAccessTime(System.currentTimeMillis());
return object.getValue();
}
@@ -313,7 +319,7 @@ public class ExpiringMap<K, V> implements Map<K, V> {
* start thread
*/
public void startExpiryIfNotStarted() {
- if (running) {
+ if (running && timeToLiveMillis <= 0) {
return;
}
startExpiring();