Aias00 commented on code in PR #7745:
URL: https://github.com/apache/shenyu/pull/7745#discussion_r4303455769
##########
shenyu-plugin/shenyu-plugin-cache/shenyu-plugin-cache-memory/src/main/java/org/apache/shenyu/plugin/cache/memory/MemoryCache.java:
##########
@@ -17,26 +17,43 @@
package org.apache.shenyu.plugin.cache.memory;
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import com.github.benmanes.caffeine.cache.Expiry;
+import com.github.benmanes.caffeine.cache.Scheduler;
import org.apache.shenyu.plugin.cache.ICache;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
-import java.util.Map;
import java.util.Objects;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
/**
* MemoryCache.
*/
public final class MemoryCache implements ICache {
- private final Map<String, Cache<String, byte[]>> mainCache;
+ private final Cache<String, byte[]> mainCache;
public MemoryCache() {
- this.mainCache = new ConcurrentHashMap<>();
+ this.mainCache = Caffeine.newBuilder()
+ .scheduler(Scheduler.systemScheduler())
+ .expireAfter(new Expiry<String, byte[]>() {
+ @Override
+ public long expireAfterCreate(final String key, final
byte[] value, final long currentTime) {
+ return 0;
Review Comment:
Non-blocking: returning `0` here means any write that does *not* go through
`expireVariably().put(...)` (a direct `mainCache.put(k, v)` added later) stores
an entry that expires immediately. Everything is correct today because
`cacheData` always uses the policy, but the invariant is invisible. Returning
`currentDuration` in `expireAfterUpdate` and throwing/documenting in
`expireAfterCreate` would make it explicit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]